quantopian / pyfolio

Portfolio and risk analytics in Python
https://quantopian.github.io/pyfolio
Apache License 2.0
5.71k stars 1.78k forks source link

The output result X-axis has no axis label #636

Closed xunfeng191 closed 4 years ago

xunfeng191 commented 4 years ago

Problem Description

How should I set up the program so that the output image x axis has an axis label? I don't know where the problem is.

My code is as follows:

df=df[['Date','returns']]
df.set_index('Date', inplace=True)
returns = df['returns'].tz_localize('UTC')
pf.create_returns_tear_sheet(returns)

The X-axis has no label as shown in figure 1(My output): 1 The X-axis has labels as shown in figure 2 (I found the right results on the Internet): 2

Versions

xunfeng191 commented 4 years ago

print(returns,type(returns))

The output is as follows: Date 2017-11-19 00:00:00+00:00 0.000000 2017-11-20 00:00:00+00:00 0.000000 2017-11-21 00:00:00+00:00 0.093333 2017-11-22 00:00:00+00:00 -0.189024 2017-11-23 00:00:00+00:00 -0.169173 ...
2020-03-04 00:00:00+00:00 -0.056218 2020-03-05 00:00:00+00:00 0.028836 2020-03-06 00:00:00+00:00 0.025817 2020-03-07 00:00:00+00:00 -0.024203 2020-03-08 00:00:00+00:00 0.029931 Name: returns, Length: 841, dtype: float64 <class 'pandas.core.series.Series'>

ssanderson commented 4 years ago

Hmm. I can't reproduce this locally. I ran the following:

rets = pd.Series(index=pd.date_range('2014', '2014-12-31', tz='utc'), data=np.random.uniform(-0.01, 0.01, 365))
pf.create_returns_tear_sheet(rets, benchmark_rets=rets)

which seems to correctly put date labels on all the plot

@xunfeng191 can you post the full code (including the input data if possible) that you're using that causes this issue?

xunfeng191 commented 4 years ago

Hmm. I can't reproduce this locally. I ran the following:

rets = pd.Series(index=pd.date_range('2014', '2014-12-31', tz='utc'), data=np.random.uniform(-0.01, 0.01, 365))
pf.create_returns_tear_sheet(rets, benchmark_rets=rets)

which seems to correctly put date labels on all the plot

@xunfeng191 can you post the full code (including the input data if possible) that you're using that causes this issue?

Thank you for your reply! I still have problems drawing the results in my environment with your code,My code is as follows:

import pandas as pd
import pyfolio as pf
%matplotlib inline
import numpy as np
rets = pd.Series(index=pd.date_range('2014', '2014-12-31', tz='utc'), data=np.random.uniform(-0.01, 0.01, 365))
pf.create_returns_tear_sheet(rets, benchmark_rets=rets)

捕获

hohosky commented 4 years ago

@xunfeng191 I'm having the same issue here, all the figures did not have X axis labels

hohosky commented 4 years ago

@xunfeng191 @ssanderson

I tried 3 versions of matplotlib 3.2.1, 3.1.3 and 3.0.1

Under 3.0.1, the X axis got displayed correctly, the other 2 version did not work.

Hope this helps

xunfeng191 commented 4 years ago

@hohosky Thank you very much. It works for me.