我已将绘图中的标签设置为希望在图表中显示的标签,但它不起作用:
sns.set(rc={"figure.figsize": (16, 8)})
ax = events_all_metrics[["event_name","kambi_payback"]].plot(x="event_name", style='.',use_index=False, color ='green', label='Kambi Payback')
events_all_metrics[["event_name","pinny_payback"]].plot(x="event_name",style='.', color='red', label='Pinnacle Payback', ax=ax)
plt.tick_params(
axis='x', # changes apply to the x-axis
which='both', # both major and minor ticks are affected
bottom='off', # ticks along the bottom edge are off
top='off', # ticks along the top edge are off
labelbottom='off')
plt.legend(loc=4, prop={'size': 15})
pinny_mean = events_all_metrics["pinny_payback"].mean()
plt.axhline(y=pinny_mean, label='Pinny Mean', linestyle='--', color='red')
kambi_mean = events_all_metrics["kambi_payback"].mean()
plt.axhline(y=kambi_mean, label='Kambi Mean', linestyle='--', color='green')
plt.show()
所以,我基本上明白了plt.图例()重写了熊猫的初始标签。我把它传到了最后(就在之前表演())使用以下代码,并且它起作用:
^{pr2}$
从数据帧打印时,pandas似乎覆盖了label命令。请看下面的例子,上面的图是直接从pandas中用
DataFrame.plot(x=...)
绘制的,而底部的则是直接用plt.plot()
绘制的matplotlib。在直接绘制序列,例如
df["series1"].plot()
也不会覆盖标签。在显然this was a behavior known as an issue in an old version of pandas所以有没有可能它没有被修复?我可以用0.20.1复制OP的问题。在
但是,可以在事实之后重命名它们,credit to this answer。例如:
^{pr2}$我还不清楚在调用
df.plot()
期间无法直接设置序列标签是有意还是无意的。在相关问题 更多 >
编程相关推荐