如何更改图表上 mplfinance 交易量的格式?

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

我正在使用 mplfinance 包来绘制股票的烛台图。我目前正在尝试弄清楚如何更改 mplfinance 中卷的格式。在包提供的所有示例中,以及在我自己的图表中,体积以 1e23 等奇怪的符号出现。我希望我的体积反映 pandas 数据框中实际的数值。我自己交易,当我在实际交易平台上的任何地方查看图表时,它显示正常,它实际上显示了交易量。但是当我查看 matplotlib、pandas、mplfinance 在线示例时,符号到处都是以一种奇怪的方式格式化。

Example of what I am talking about

体积符号根据体积的大小自动呈指数形式,所以如果你想避免这种情况,你可以通过使用单位数据使原始数据变小来避免它。下面的例子展示了如何通过除以 100 万来处理这个问题。此数据取自 official website.

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

这就是我们的回应。

%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')

正常输出示例

或者,以科学计数法显示体积 not,但保持原始值(未按比例缩小)...使用与@r-beginners ...

的答案相同 data/code
fig, axlist = mpf.plot(daily,type='candle',volume=True,
                       title='\nS&P 500, Nov 2019',
                       ylabel='OHLC Candles',
                       ylabel_lower='Shares\nTraded',
                       returnfig=True)

import matplotlib.ticker as mticker
axlist[2].yaxis.set_major_formatter(mticker.FormatStrFormatter('%d'))
mpf.show()

结果:

从理论上讲,增强 mplfinance 以接受用于格式化轴标签的 kwarg 会相对容易;但现在上面的方法可行。