mplfinance 中的独立面​​板

问题描述

我想分开我的面板,因为标题是重叠的。 ADX 标题在 RSI 面板中。我试过 tight_layout=True 但还是一样。

我的代码

        ap0 = [
        mpf.make_addplot(df['sma_200'],color='#FF0000',panel=2),mpf.make_addplot(df['sma_50'],color='#ffa500',mpf.make_addplot(df['sma_20'],color='#00FF00',mpf.make_addplot(df['rsi'],panel=0,title="RSI"),mpf.make_addplot(df['hline_30'],panel=0),mpf.make_addplot(df['hline_70'],mpf.make_addplot(df['adx'],color='#0000FF',panel=1,secondary_y=False,title="ADX"),mpf.make_addplot(df['-di'],secondary_y=False),mpf.make_addplot(df['+di'],color='#32cd32',mpf.make_addplot(df['hline_25'],secondary_y=False)
    ]
    fig,axlist = mpf.plot(
        df,panel_ratios=(.05,.05,.2,.05),type="hollow_candle",yscale='log',volume=True,title="{} - {}".format(ticker,interval),style=mpf_style,figsize=(12.8,10),returnfig=True,closefig=True,addplot=ap0,main_panel=2,volume_panel=3,num_panels=4,)

enter image description here

解决方法

Mplfinance 子图没有调整图形间距的功能,因此有一种方法可以将它们放入 matplotlib 子图中并使它们间隔开。我们建议使用 y 轴标签而不是标题,这是一项仅在 Mplfinance 中可用的功能。

import yfinance as yf
import mplfinance as mpf
import matplotlib.pyplot as plt

df = yf.download("AAPL",start="2021-01-01",end="2021-07-01")
df['sam_20'] = df['Close'].rolling(20).mean()
df['sam_50'] = df['Close'].rolling(50).mean()
fig = mpf.figure(style='yahoo',figsize=(7,8))
ax1 = fig.add_subplot(4,1,sharex=ax4)
ax2 = fig.add_subplot(4,2,sharex=ax4)
ax3 = fig.add_subplot(4,3,sharex=ax4)
ax4 = fig.add_subplot(4,4)

ap0 = [
    mpf.make_addplot(df['sam_20'],color='#00FF00',panel=0,title='sma_20',ax=ax1),mpf.make_addplot(df['sam_50'],color='#FFa500',panel=1,title='sma_50',ax=ax2)
]

mpf.plot(df,ax=ax3,addplot=ap0,volume=ax4,)
fig.subplots_adjust(hspace=0.2)
ax1.tick_params(labelbottom=False)
ax2.tick_params(labelbottom=False)
ax3.tick_params(labelbottom=False)
ax3.yaxis.set_label_position('left')
ax3.yaxis.tick_left()

enter image description here

另一种解决方案

ap0 = [
    mpf.make_addplot(df['sam_20'],ylabel='sma_20'),ylabel='sma_50')
]

enter image description here

@Daniel Goldfarlb 解决方案

ap0 = [
    mpf.make_addplot(df['sam_20'],ylim=(110,140)),title='sma_50')
]

mpf.plot(
        df,panel_ratios=(2,1),type="hollow_candle",yscale='log',volume=True,style='yahoo',figsize=(12.8,10),main_panel=2,volume_panel=3,num_panels=4,)

enter image description here

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...