pythondatetimemplfinance

mplfinance : i dont want it to show date


I want that the figure does not show the date on a specific subplot

I did find nothing on internet including stackoverflow, and the doc of mplfinance

import matplotlib.pyplot as plt
import matplotlib
import numpy as np
import pandas as pd
import mplfinance as mpf
import datetime as dt


fig= mpf.figure(style="yahoo",figsize=(12,8))



 axlist=[ fig.add_subplot(2,1,1)]
 axlist.append(fig.add_subplot(2,1,2,sharex=axlist[0] ))

df = pd.read_csv('df.txt', index_col=0,parse_dates=True)

mpf.plot(df, type="candle", returnfig=True, ax=axlist[0], volume = axlist[1])
mpf.show()

enter image description here


Solution

  • Mplfinance already does this for you if you let it.

    In order to do this (for the type of plot that you are making, and in fact for most plots) do not use external axes. When you do use external axes, you prevent mplfinance from doing these types of things for you (and you end up having to write a lot more code to do it yourself).

    You should read carefully through the mplfinance tutorial on "panels" to see exactly how to do what you are trying to accomplish (i.e. with no axes labels in between the panels).

    Essentially your code should look like this:

    # DELETE THIS LINE: fig= mpf.figure(style="yahoo",figsize=(12,8))
    # DELETE THIS LINE: axlist=[ fig.add_subplot(2,1,1)]
    # DELETE THIS LINE: axlist.append(fig.add_subplot(2,1,2,sharex=axlist[0] ))
    
    df = pd.read_csv('df.txt', index_col=0, parse_dates=True)
    
    mpf.plot(df, type="candle", style='yahoo', volume=True, panel_ratios=(1,1))
    
    mpf.show()
    

    NOTICE that I have added the kwarg panel_ratios=(1,1). This is because in your plot you made the candlestick panel and the volume panel the same size, and I am assuming you wanted it that way on purpose. Notice also that there is no need for returnfig=True.


    If you still insist on using external axes (which I strongly do not recommmend) then you can remove the x-axis labels with axlist[0].xaxis.set_tick_params(labelbottom=False).