在python线情节添加次要y-轴[复制]

问题描述 投票:0回答:2

这个问题已经在这里有一个答案:

我要添加次Y轴。我有我的CSV三个日,喉癌和CC数据。我想LSCC添加为第一y轴和CC作为secondry。到目前为止,我已经做到了这一点

df=pd.read_csv("E29Lsccvalue.csv", index_col='Date' )
plt.ylabel("")
plt.xlabel("Low level Similarity Class Cohesion (LSCC) Evolution")
df.plot(kind="line", marker='o',legend=None)
plt.xticks(rotation=90)
plt.show()

谢谢

python matplotlib
2个回答
1
投票

在matplotlib我用twinx()时,我想利用我已经创建了现有的X轴,又有着不同的Y轴绘制在上面更多的数据。在你的情况与df作为第一个剧情对象:

axCC = df.twinx() # second axis sharing the same X axis of the original

然后,可将地块,标签,并参照通过调用如该轴的其他参数:

axCC.set_ylabel("ExampleLabel",color="tab:red")
axCC.plot(xData,yData,color="blue")

等等,等等。

用更详细的一个功能齐全的例子示here


1
投票

虽然没有提供可重复的日期,我想你可以实现通过这样期望的结果:

ax = df.plot(secondary_y='CC')

最终将需要所有ax定制

编辑:虚线定制

假定需要在您的x轴的某个位置处的垂直虚线(在这个例子中,在从大熊猫索引位置2)中,使用axvline':'如线型(点)

ax = a.plot(secondary_y='Price')
ax.axvline(a.index.values[2], linestyle=':')
© www.soinside.com 2019 - 2024. All rights reserved.