Closed gnyuan closed 4 years ago
What happens if you call plt.tight_layout()
?
What happens if you call
plt.tight_layout()
?
No, I just copy two lines according to the document. Maybe there is something to do with OS env?
# factors_df and prices_df are dataframe which formatted.
factor_data = alphalens.utils.get_clean_factor_and_forward_returns(factors_df['turnover_rate'],prices_df)
alphalens.tears.create_returns_tear_sheet(factor_data)
I have figured out what happen. I'm running on PyCharm. In PyCharm Python is in interactive mode, and the maximum figsize of a matplotlib figure is limited. We should first add two lines in the beginning, which makes matplotlib using Agg backen to draw figures and it will break the limit of figsize.
import matplotlib
matplotlib.use('Agg')
then in close
method of tears.py, save figure as a png file.
def close(self):
plt.savefig('output.png')
plt.close(self.fig)
self.fig = None
self.gs = None
Thanks to these two links. https://stackoverflow.com/questions/50257509/is-there-maximum-figsize-in-matplotlib https://stackoverflow.com/questions/49284893/matplotlib-while-debugging-in-pycharm-how-to-turn-off-interactive-mode
Thanks for posting the solution!
Problem Description
I'm runinng on Windows 10, and it outputs a mess up figure.
Versions