【问题标题】:Marker doesn't appear or get overwritten by line标记没有出现或被行覆盖
【发布时间】:2021-01-08 15:47:09
【问题描述】:

在我的桌面上使用 Sppyder 运行此代码可以正确显示标记。在我的笔记本电脑上使用相同的代码并且不再显示它们。

我有相同的 spyder (python 3.7) 版本。如果我反转代码行并将市场放在行之前,我可以看到它们,但是行越过了标记。我想要的是越界标记。


fig = plt.figure()

ax1 = fig.add_subplot(111,  ylabel='Price in $')

df_MA.iloc[:,0].plot(ax=ax1, color='k', lw=1.)

df_MA[['short_MA', 'long_MA']].plot(ax=ax1, lw=2.)

ax1.plot(df_MA.loc[df_MA.positions == 1.0].index, df_MA.short_MA[df_MA.positions == 1.0],'^', markersize=10, color='g')
         
ax1.plot(df_MA.loc[df_MA.positions == -1.0].index, df_MA.short_MA[df_MA.positions == -1.0], 'v', markersize=10, color='r')

plt.show()

【问题讨论】:

    标签: python matplotlib marker overwrite


    【解决方案1】:

    使用函数Zorder 并将我的标记代码行放在第一个工作中。

    fig = plt.figure()
    
    ax1 = fig.add_subplot(111,  ylabel='Price in $')
    
    ax1.plot(df_MA.loc[df_MA.positions == 1.0].index, df_MA.short_MA[df_MA.positions == 1.0],'^', markersize=10, color='g', zorder=2)
             
    ax1.plot(df_MA.loc[df_MA.positions == -1.0].index, df_MA.short_MA[df_MA.positions == -1.0], 'v', markersize=10, color='r', zorder=2)
    
    df_MA.iloc[:,0].plot(ax=ax1, color='k', lw=1., zorder=0)
    
    df_MA[['short_MA', 'long_MA']].plot(ax=ax1, lw=2., zorder=1)
    
    plt.show()
    

    【讨论】:

      猜你喜欢
      • 2019-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-25
      相关资源
      最近更新 更多