pyfolio icon indicating copy to clipboard operation
pyfolio copied to clipboard

Unable to display date as x-axis when using "create_returns_tear_sheet"

Open jackylawtrading opened this issue 3 years ago • 4 comments

Problem Description

I am not able to display the date as x-axis when using "create_returns_tear_sheet". All of the plots can only display their y-labels but not for x-labels (blank there).

Please see the following codes. I used it to generate the plots:

import pandas as pd
import numpy as np
import pyfolio as pf
import matplotlib.pyplot as plt
%matplotlib inline 
import warnings
warnings.filterwarnings('ignore')

df = pd.read_excel("index.xlsx")
df = df.fillna(0)

df = df[df['daily ret']!=0]
len(df) # double checked the removal of rows with daily ret as zero is correct

df['Date'] = pd.to_datetime(df['Date'],format='%Y-%m-%d')

df=df[['Date','daily ret']]
df.set_index('Date', inplace=True)
returns = df['daily ret']

pf.create_returns_tear_sheet(returns,
                            positions=None,
                            transactions=None,
                            cone_std=(1.0,1.5,2.0),
                            benchmark_rets=None,
                            bootstrap=False,
                            header_rows=None,
                            return_fig=False)

jackylawtrading avatar Apr 13 '21 04:04 jackylawtrading

same here, any solution?

slps20425 avatar Apr 14 '21 09:04 slps20425

Removing every sharex=ax_rolling_returns from def create_returns_tear_sheet fixed this for me.

Biszu avatar Apr 19 '21 14:04 Biszu

I am having the same issue.

sometxdude avatar Apr 19 '21 16:04 sometxdude

You can downgrade matplotlib. pip install matplotlib==2.2.5

Or patch it as below, by following the wisdom of : https://stackoverflow.com/questions/51553545/matplotlib-tick-labels-disappeared-after-set-sharex-in-subplots

stock_rets = pf.utils.get_symbol_rets('FB')
fig = pf.create_returns_tear_sheet(stock_rets, return_fig=True)

for ax in fig.axes:
        ax.tick_params(
        axis='x',           # changes apply to the x-axis
        which='both',       # both major and minor ticks are affected
        bottom=True,
        top=False,
        labelbottom=True)    # labels along the bottom edge are on

(tested with matplotlib: 3.4.2)

yitelee avatar Jun 26 '21 08:06 yitelee