Search code examples
pythonmatplotlibfinancemplfinance

How can I change the formatting of the mplfinance volume on the chart?


I am using mplfinance package to plot candlestick charts of the stock. I am currently trying to figure out how can I change the formatting of the volume in the mplfinance. In all examples provided by the package, and in my own chart the volume comes out in strange notation like 1e23 etc. I would like my volume to reflect the numerical value of what is actually in the pandas dataframe. I trade myself and when I am looking at charts anywhere on the actual trading platforms, it shows normal, it actually shows the volume. But when I look at matplotlib, pandas, mplfinance examples online, the notations is formatted in a strange way everywhere.

Example of what I am talking about


Solution

  • The volume notation is automatically in exponential form based on the size of the volume, so if you want to avoid this, you can avoid it by making the original data smaller with unit data. The following example shows how to deal with this problem by dividing by 1 million. This data is taken from the official website.

    daily['Volume'] = daily['Volume'] / 1000000
    

    This is how we responded.

    %matplotlib inline
    import pandas as pd
    
    daily = pd.read_csv('data/SP500_NOV2019_Hist.csv',index_col=0,parse_dates=True)
    daily['Volume'] = daily['Volume'] / 1000000
    
    import mplfinance as mpf
    
    mpf.plot(daily,type='candle',volume=True,
             title='\nS&P 500, Nov 2019',
             ylabel='OHLC Candles',
             ylabel_lower='Shares\nTraded')
    

    enter image description here

    Example of normal output

    enter image description here