quantopian / alphalens

Performance analysis of predictive (alpha) stock factors
http://quantopian.github.io/alphalens
Apache License 2.0
3.18k stars 1.12k forks source link

the Tear Sheet is not showing good. #366

Closed gnyuan closed 4 years ago

gnyuan commented 4 years ago

Problem Description

I'm runinng on Windows 10, and it outputs a mess up figure.

1111

# I look into codes in tears.py, everything looks good. 
# maybe this is the place where to set height of subplots. 
self.fig = plt.figure(figsize=(14, rows * 7))
self.gs = gridspec.GridSpec(rows, cols, wspace=0.4, hspace=0.3)

Versions

twiecki commented 4 years ago

What happens if you call plt.tight_layout()?

gnyuan commented 4 years ago

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)
gnyuan commented 4 years ago

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

twiecki commented 4 years ago

Thanks for posting the solution!