首先必须说,我喜欢mplfinance,它是在图表上显示数据的一种非常好的方式
我现在的问题是,我无法将空间缩小到边界。有一个称为“紧密布局”的参数,但它会切断信息。也许我做错了什么
mpf.plot(df_history, show_nontrading=True, figratio=(10,7), figscale=1.5, datetime_format='%d.%m.%y',
xrotation=90, tight_layout=True,
alines=dict(alines=seq_of_points, colors=seq_of_colors, linestyle='-', linewidths=0.5),
type='candle', savefig=bildpfad, addplot=apdict,
update_width_config=dict(candle_linewidth=0.4))
当我使用tight_layout=True
时,它看起来是这样的:
图表周围的空间是完美的,但图表中的数据被切断
如果我使用tight_layout=False
,它会占用太多的空间,并且创建的html文件看起来是扭曲的。
有人知道正确的方法吗
你可以做一些不同的事情来解决这个问题。首先,了解发生这种情况的原因。
tight_layout
算法将x轴限制设置为刚好超出数据帧日期时间索引的限制,而某些alines
点显然超出了该范围。鉴于此,您可以做以下几件事:xlim=(xmin,xmax)
手动设置所需的x轴限制李>nan
值填充ohlc数据框的末尾,直到绘图上需要的最新日期李>tight_layout
应该考虑的bug修复或增强李>嗯
p.S.目前
xlim
只接受与数据帧中的行号相对应的数字(int或float)(或与matplotlib日期相对应的数字,请参见下面的p.p.S.)。我希望不久的某个时候能接受约会。同时,试着这样做:p.p.S.我刚刚意识到上述(
xmax = len(df_history)*1.4
)将只适用于show_nontrading=False
。但是,如果使用show_nontrading=True
,则需要以不同的方式设置xmax和xmin,如下所示:(请注意,上面的两个函数都不是
.index[0]
,而是xmax派生自.index[-1]
)我很抱歉,上述针对
xlim
的解决方案过于详细。这更激励我完成xlim
增强功能,这样用户就可以将日期作为字符串或日期时间传入。mplfinance的用户不必担心这些日期转换细节相关问题 更多 >
编程相关推荐