[英]Pandas Time Series Plot: Secondary y-Axis Label , Set Lower Limit
I would like to have a time series plot including 2 columns - which works fine the way described below.我想要一个包含 2 列的时间序列 plot - 它的工作原理如下所述。 I tried many ways to introduce a label for the secondary y axis with no success.我尝试了多种方法来为辅助 y 轴引入 label,但均未成功。
df.plot(kind='line',
x='measurement_date',
y=['crack_total', "crack_inv_vel"],
secondary_y=["crack_inv_vel"],
xlabel="date",
ylabel="crack width [m]",
title="crack survey")
Example Plot as produced with the code above:-使用上述代码生成的示例 Plot:-
Assign the return value of df.plot
to a variable;将df.plot
的返回值赋给一个变量; it will be of type matplotlib.axes._subplots.AxesSubplot
.它将是matplotlib.axes._subplots.AxesSubplot
类型。 Then twinx
it to get access to the secondary y-axis.然后twinx
它以访问辅助 y 轴。 Then you can adjust label etc.:然后可以调整label等:
ax = df.plot(kind="line",
x="measurement_date",
y=["crack_total", "crack_inv_vel"],
secondary_y=["crack_inv_vel"],
xlabel="date",
ylabel="crack width [m]",
title="crack survey")
ax_secondary = ax.twinx()
ax_secondary.set_ylabel("secondary y-label")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.