如何在 mplfinance 图中添加一条简单的水平线?

How to add a simple horizontal line to mplfinance plot?

我知道这听起来可能太简单了,但它让我卡住了! 我有一个使用 fplt 的蜡烛图,我只是想在其中添加一条水平线,但不确定如何添加!

ax = fplt.plot(
                result,
                type='candle',
                style = 'charles',
                title='whatever!',
                ylabel='anything',figsize=(24,8)
            )

这创建了我想要的蜡烛图,非常漂亮! 但后来我使用 ax.axhline(...) 但给我错误或者我使用 ax.plt(x_coordinates,y_coordinates) 但再次错误: 'NoneType' object has no attribute 'plt'

有人可以让我的生活更轻松吗?!我只想在这里加一条横线! 谢谢

简要阅读介绍 https://pypi.org/project/finplot/ 它看起来像 fplt.plot returns None (然后您将其分配给 ax)并且您应该得到轴来自 fplt.create_plot()

使用 mplfinance,这就像阅读 mplfinance documentation, specifically the section titled Trends, Support, Resistance, and Trading Lines

一样简单

你可以看到这就像使用 hlines kwarg 一样简单:

此外,mpf.plot()(或者如您所写的非常规,fplt.plot())returns None,除非您设置 kwarg returnfig=True,但对于你想做的事情,没有理由access the Figure or Axes objects

hth