如何在pandas df图中添加水平线?

11 浏览
0 Comments

如何在pandas df图中添加水平线?

我想在y=0上画一条线。然而,我不确定如何使用pandas内置的图表绘制这样的线。我正在运行df.mean(axis=1).plot(),这是结果。[图片链接](https://i.stack.imgur.com/qi2ge.png)

0
0 Comments

问题:如何在pandas的df图中添加水平线?

原因:用户想要在pandas的df图中添加水平线。

解决方法:通过捕获plot返回的ax实例,并使用axhline方法添加水平线。

代码和输出如下:

ax = df.mean(axis=1).plot()
ax.axhline(0, c='r')

输出图像如下:

![enter image description here](https://i.stack.imgur.com/7SxeH.png)

0