简体   繁体   English

使用 mplfinance 在同一面板上的 OHLC 和体积数据

[英]OHLC and Volume Data on the same Panel using mplfinance

Is there a way to plot the volume and OHLC data on the same panel?有没有办法在同一个面板上绘制体积和 OHLC 数据?

I tried putting the panel IDs same for both but that only plots the volume data (I guess the volume data is plotted onto later, and hence replaces the OHLC data?).我尝试为两者设置相同的面板 ID,但只绘制体积数据(我猜体积数据是稍后绘制的,因此替换了 OHLC 数据?)。

    kwargs = {
        'type': "candle",
        'volume': True,
        'volume_panel': 0,
        'main_panel': 0,
        'mav': (6,9),
        'title': f"{self.meta['2. Symbol']}",
        'show_nontrading': True,
        'style': self.plotStyle,
        'addplot': adps
    }

    mplf.plot(self.ohlcv, **kwargs)

Example with the code代码示例

Mplfinance actually is plotting both OHLC and Volume. Mplfinance 实际上正在绘制 OHLCVolume。

The problem is that the prices and volume are being plotted on the same y-axis and, most likely, your volume values are several or many orders of magnitude greater than the prices.问题是价格和交易量被绘制在同一 y 轴上,并且很可能您的交易量值比价格大几个或多个数量级。 Thus you don't see the prices.因此,您看不到价格。

The workaround for this is to plot either volume, or ohlc, separately using mpf.make_addplot()解决方法是分别使用mpf.make_addplot()绘制体积或 ohlc

(use type='bar' for volume, and type='ohlc' or type='candle' for ohlc data). (使用type='bar'表示音量, type='ohlc'type='candle'表示 ohlc 数据)。 In the call to mpf.make_addplot() you then may need to set secondary_y=True (or it may work automatically).在对mpf.make_addplot()的调用中,您可能需要设置secondary_y=True (或者它可能会自动工作)。


Alternatively, your question gave me the idea to enhance mplfinance to automatically put the volume on the secondary axes if it detects that the ohlc and volume data are on the same panel.或者,如果检测到 ohlc 和体积数据在同一个面板上,您的问题给了我增强 mplfinance 以自动将体积放在辅助轴上的想法。 Thus you can avoid the need to call make_addplot() in order to place one of them on the secondary axes.因此,您可以避免调用make_addplot()以便将其中一个放置在辅助轴上。

This enhancement is in mplfinance version v0.12.9b1 , so you will need to install that version.此增强功能位于 mplfinance 版本v0.12.9b1中,因此您需要安装该版本。 With this enhancement, all you have to do is what you tried above, that is, simply set volume_panel and main_panel to the same value and everything should work automatically.有了这个增强功能,您所要做的就是上面尝试的操作,即只需将volume_panelmain_panel设置为相同的值,一切都会自动运行。

With this enhancement, there are two addition kwargs to mpf.plot() that you may find useful:通过此增强功能,您可能会发现mpf.plot()中添加了两个有用的 kwarg:

  • volume_alpha= to set the opacity of the volume bars (in case you want them to be lighter or more transparent, allowing the ohlc data to be more apparent and/or stand out. volume_alpha=设置音量条的不透明度(如果您希望它们更轻或更透明,让 ohlc 数据更明显和/或突出。
  • volume_ylim= to be able to set the y-axis minumum and maximum for the volume, in case you want the volume bars to be somewhat smaller in appearance (by setting the volume_ylim maximum to a value significantly larger than the maximum volume). volume_ylim=能够设置音量的 y 轴最小值和最大值,以防您希望音量条在外观上稍微小一些(通过将volume_ylim最大值设置为显着大于最大音量的值)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM