quantopian / pyfolio

Portfolio and risk analytics in Python

Home Page:https://quantopian.github.io/pyfolio

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

jackylawtrading opened this issue · 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)

commented

same here, any solution?

commented

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

I am having the same issue.

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)