mplfinance icon indicating copy to clipboard operation
mplfinance copied to clipboard

How to get more date labels?

Open PowerrNuller opened this issue 4 years ago • 2 comments

The existing library is sparse on placing date labels at the bottom of the charts - is there a way to customize how many show up and/or the frequency of the date labels.

PowerrNuller avatar Jul 22 '20 13:07 PowerrNuller

There is nothing yet built into mplfinance to do this.

You can get access to matplotlib Axes objects (either via returnfig=True, or via external axes and from there you have access to methods such as set_xticks and tick locators, etc.

DanielGoldfarb avatar Aug 09 '20 19:08 DanielGoldfarb

@PowerrNuller This worked for me, just adjust your base and offset as needed

image

fig, ax = mpf.plot( df_slice, **kwargs, addplot=ichi_lines ); # matplotlib figure xtick = 1; # each timestamp of dataframe on x axis ytick = round(last/100, 2); # 1% price ticks on y axis ax[0].xaxis.set_major_locator(ticker.IndexLocator(base=xtick, offset=0) ); ax[0].yaxis.set_major_locator(ticker.IndexLocator(base=ytick, offset=0) );
if ( ( bar_lngth == 15 ) or (bar_lngth == 30) ) : fig.suptitle(sym + ' ' + str(bar_lngth) + 'min'); elif(( bar_lngth == 60 ) or (bar_lngth == 120) or (bar_lngth == 240) ) : fig.suptitle(sym + ' ' + str(int(bar_lngth/60)) + 'hr'); plt.show();

justinabate avatar Aug 14 '20 22:08 justinabate