在绘图中添加多行

问题描述 投票:1回答:1

添加多个hlines进行绘图。 xstart和xfinsh值位于pandas数据帧中

xstart  xfinish
0.00    6.30
37.45   43.95
57.16   64.73
64.73   71.97
76.49   82.79
84.65   92.77
125.48  131.69
131.69  139.98

我想在每个行的图上添加一个hline。 hline的y值是y = 1。

我试过这个:

plt.hlines(1,xstart ,xfinish)

但它不起作用。

python pandas matplotlib
1个回答
1
投票

你需要传递yxminxmax等长的数组。使用:

plt.hlines([1] * len(df), df['xstart'], df['xfinish'])

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.