Решение
Использование plt.axhline
:
import matplotlib.pyplot as plt
import pandas as pd
df2 = pd.DataFrame([[19.6, 2.3, -5.8]], columns=['Real Estate', 'Industrials', 'Utilities'])
df2.plot(kind='bar')
# the c='k' kwarg sets the line's color to blac(k)
plt.axhline(0, c='k')
plt.xticks([])
plt.axis("tight")
Выход:
![enter image description here](https://i.stack.imgur.com/JsoSQ.png)
Изменить внешний вид горизонтальной линии
axhline
поддерживает все виды опций. Для более тонкой пунктирной линии сделайте:
# ls is short for linestyle, and lw is short for linewidth
plt.axhline(0, c='k', ls='--', lw=.5)
Выход:
![enter image description here](https://i.stack.imgur.com/qq46Q.png)