如何解决标记未显示或被行覆盖
在我的桌面上使用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',color='r')
plt.show()
解决方法
使用功能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',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()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。