更改mplfinance图表样式时“ returnfig = true”在代码中的任何地方都没有接受

发布于 2025-02-12 22:24:54 字数 1567 浏览 1 评论 0原文

我试图在使用MPF.plot和Fig.Add_Axes绘制的多个图表中更改轴标题和字体大小,以将它们放在屏幕上。

我已经理解了此链接中给出的过程和示例如何更改MPLFINANCE标题的字体大小和字体类型以及在GitHub上讨论该方法,但它不适用于我的代码。我将“ returnfig = true”放置在任何地方都会导致错误。

这是我相关部分的代码段

fig = mpf.figure(figsize=(12,8),style='yahoo')

ax1 = fig.add_axes([0.05,0.70,0.3,0.25]) # ax = fig.add_axes([left,bottom,width,height])
ax2 = fig.add_axes([0.05,0.65,0.3,0.05])

ax3 = fig.add_axes([0.36,0.70,0.3,0.25])
ax4 = fig.add_axes([0.36,0.65,0.3,0.05])

ax5 = fig.add_axes([0.68,0.70,0.3,0.25])
ax6 = fig.add_axes([0.68,0.65,0.3,0.05])

ax7 = fig.add_axes([0.05,0.25,0.3,0.25])
ax8 = fig.add_axes([0.05,0.20,0.3,0.05])

ax9 = fig.add_axes([0.36,0.25,0.3,0.25])
ax10 = fig.add_axes([0.36,0.20,0.3,0.05])

ax11 = fig.add_axes([0.68,0.25,0.3,0.25])
ax12 = fig.add_axes([0.68,0.20,0.3,0.05])

mpf.plot(ausd,type='candle',ax=ax1,volume=ax2, mav=(9), show_nontrading=False, axtitle='M6A=F')
mpf.plot(gbpf,type='candle',ax=ax3,volume=ax4, mav=(9), show_nontrading=False, axtitle='M6B=F')
mpf.plot(cadf,type='candle',ax=ax5,volume=ax6, mav=(9), show_nontrading=False, axtitle='M6E=F')
mpf.plot(btcf,type='candle',ax=ax7,volume=ax8, mav=(9), show_nontrading=False, axtitle='M6C=F')
mpf.plot(gldf,type='candle',ax=ax9,volume=ax10, mav=(9), show_nontrading=False, axtitle='MBT=F')
mpf.plot(slvf,type='candle',ax=ax11,volume=ax12, mav=(9), show_nontrading=False, axtitle='MGC=F')

I am trying to change the axis titles and font size in multiple charts that are plotted using mpf.plot and fig.add_axes to place them on screen.

I have understood the process and examples given in this link How to change font size and font type in mplfinance title and on the github discussing the approach, but it will not work with my code. Anywhere I put "returnfig=True" it causes errors.

Here is my code snippet of the relevant section

fig = mpf.figure(figsize=(12,8),style='yahoo')

ax1 = fig.add_axes([0.05,0.70,0.3,0.25]) # ax = fig.add_axes([left,bottom,width,height])
ax2 = fig.add_axes([0.05,0.65,0.3,0.05])

ax3 = fig.add_axes([0.36,0.70,0.3,0.25])
ax4 = fig.add_axes([0.36,0.65,0.3,0.05])

ax5 = fig.add_axes([0.68,0.70,0.3,0.25])
ax6 = fig.add_axes([0.68,0.65,0.3,0.05])

ax7 = fig.add_axes([0.05,0.25,0.3,0.25])
ax8 = fig.add_axes([0.05,0.20,0.3,0.05])

ax9 = fig.add_axes([0.36,0.25,0.3,0.25])
ax10 = fig.add_axes([0.36,0.20,0.3,0.05])

ax11 = fig.add_axes([0.68,0.25,0.3,0.25])
ax12 = fig.add_axes([0.68,0.20,0.3,0.05])

mpf.plot(ausd,type='candle',ax=ax1,volume=ax2, mav=(9), show_nontrading=False, axtitle='M6A=F')
mpf.plot(gbpf,type='candle',ax=ax3,volume=ax4, mav=(9), show_nontrading=False, axtitle='M6B=F')
mpf.plot(cadf,type='candle',ax=ax5,volume=ax6, mav=(9), show_nontrading=False, axtitle='M6E=F')
mpf.plot(btcf,type='candle',ax=ax7,volume=ax8, mav=(9), show_nontrading=False, axtitle='M6C=F')
mpf.plot(gldf,type='candle',ax=ax9,volume=ax10, mav=(9), show_nontrading=False, axtitle='MBT=F')
mpf.plot(slvf,type='candle',ax=ax11,volume=ax12, mav=(9), show_nontrading=False, axtitle='MGC=F')

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

遇见了你 2025-02-19 22:24:55

这是 两种方式 可以访问MplFinance使用的图形和轴对象。 >

1。如果使用 returnfig = true ,则表示 mpf.plot() 正在内部创建图形和轴对象,然后将它们返回给您以进行进一步的操作 you 最终调用mpf.show()图savefig()完成图。

2。,但是,如果您创建 您自己的 figue and轴对象 外部 to mpf.plot()即使您使用mpf.figure() 来创建图对象,然后 mpf.plot() do 不是 自己的图形和轴对象,因此无法将它们返回给您!
实际上,您已经拥有它们并拥有它们,因此没有意义来返回它们!这就是为什么当mpf.plot()>检测您已将轴传递到其中(因此处于“外部轴模式”),然后它将拒绝Kwarg returnfig ,因为在这种情况下,返回图形和轴是没有任何意义的你已经拥有了。

The are two ways to gain access to the Figure and Axes objects that mplfinance uses. These two ways are documented here.

1. If you use returnfig=True it means that mpf.plot() is creating the Figure and Axes objects internally, and returning them to you for further manipulation before you eventually call mpf.show() or fig.savefig() to complete the plot.

2. However, if you create your own Figure and Axes objects externally to mpf.plot(), even if you use mpf.figure() to create the Figure object, then mpf.plot() does not own the Figure and Axes objects, and so cannot return them to you!
In fact, you already have them and own them so there is no point to returning them! This is why, when mpf.plot() detects that you have passed Axes into it (thus it is in "External Axes Mode") then it will reject the kwarg returnfig because in that context it doesn't make any sense to return a Figure and Axes that you already have.

春夜浅 2025-02-19 22:24:55

我知道,如果您要在设置每个面板时访问returnfig = true,则需要。我的理解可能仍然缺乏。如果您设置了带有其他轴的子图,我认为您不需要returnfig = true。在上一个问题中使用股票程序完成图表将导致以下代码。我引入了循环处理,缩短了长期格式,并降低了股票方向。

myTickers = ['M6A=F','M6B=F','M6C=F','M6E=F','MBT=F','MGC=F']
fig = mpf.figure(figsize=(12,12), style='yahoo')

ax1 = fig.add_axes([0.05,0.70,0.25,0.25]) 
ax2 = fig.add_axes([0.05,0.60,0.25,0.08])

ax3 = fig.add_axes([0.36,0.70,0.25,0.25])
ax4 = fig.add_axes([0.36,0.60,0.25,0.08])

ax5 = fig.add_axes([0.68,0.70,0.25,0.25])
ax6 = fig.add_axes([0.68,0.60,0.25,0.08])

ax7 = fig.add_axes([0.05,0.25,0.25,0.25])
ax8 = fig.add_axes([0.05,0.15,0.25,0.08])

ax9 = fig.add_axes([0.36,0.25,0.25,0.25])
ax10 = fig.add_axes([0.36,0.15,0.25,0.07])

ax11 = fig.add_axes([0.68,0.25,0.25,0.25])
ax12 = fig.add_axes([0.68,0.15,0.25,0.08])

for i,(t,ax) in enumerate(zip(myTickers,[[ax1,ax2],[ax3,ax4],[ax5,ax6],[ax7,ax8],[ax9,ax10],[ax11,ax12]])):
    dff = df.loc[:,t]
    mpf.plot(dff, type='candle',
             ax=ax[0],
             volume=ax[1],
             mav=(9),
             show_nontrading=False,
             axtitle=t,
             datetime_format='%b %d',
             xrotation=30)
    
for ax in [ax1,ax3,ax5,ax7,ax9,ax11]:
    ax.set_xticklabels([])

I understand that returnfig=True is required if you want to access each of the panels when they are set up. My understanding may still be lacking. If you set up a subplot with additional axes, I don't think you need returnfig=True. Completing the graph with the ticker in the previous question would result in the following code. I introduced loop processing, shortened the long date format, and reduced the orientation of the ticker.

myTickers = ['M6A=F','M6B=F','M6C=F','M6E=F','MBT=F','MGC=F']
fig = mpf.figure(figsize=(12,12), style='yahoo')

ax1 = fig.add_axes([0.05,0.70,0.25,0.25]) 
ax2 = fig.add_axes([0.05,0.60,0.25,0.08])

ax3 = fig.add_axes([0.36,0.70,0.25,0.25])
ax4 = fig.add_axes([0.36,0.60,0.25,0.08])

ax5 = fig.add_axes([0.68,0.70,0.25,0.25])
ax6 = fig.add_axes([0.68,0.60,0.25,0.08])

ax7 = fig.add_axes([0.05,0.25,0.25,0.25])
ax8 = fig.add_axes([0.05,0.15,0.25,0.08])

ax9 = fig.add_axes([0.36,0.25,0.25,0.25])
ax10 = fig.add_axes([0.36,0.15,0.25,0.07])

ax11 = fig.add_axes([0.68,0.25,0.25,0.25])
ax12 = fig.add_axes([0.68,0.15,0.25,0.08])

for i,(t,ax) in enumerate(zip(myTickers,[[ax1,ax2],[ax3,ax4],[ax5,ax6],[ax7,ax8],[ax9,ax10],[ax11,ax12]])):
    dff = df.loc[:,t]
    mpf.plot(dff, type='candle',
             ax=ax[0],
             volume=ax[1],
             mav=(9),
             show_nontrading=False,
             axtitle=t,
             datetime_format='%b %d',
             xrotation=30)
    
for ax in [ax1,ax3,ax5,ax7,ax9,ax11]:
    ax.set_xticklabels([])

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文