<p>我将认为这是一个错误,即条的y位置分配不正确。不过,修补程序相对简单:</p>
<p>这只是一个正确的顺序,那叫做…,正确的顺序。任何不正确的命令,都是错误的命令。:p页</p>
<pre><code>In [63]:
print df
Total_beef_cattle Total_dairy_cattle Total_sheep Total_deer \
1994 0.000000 0.000000 0.000000 0.000000
2002 -11.025827 34.444950 -20.002034 33.858009
2003 -8.344764 32.882482 -20.041908 37.229441
2004 -11.895128 34.207998 -20.609926 42.707754
2005 -12.366101 32.506699 -19.379727 38.499840
Total_pigs Total_horses
1994 0.000000 0.000000
2002 -19.100637 11.811093
2003 -10.766476 18.504488
2004 -8.072078 13.376472
2005 -19.230733 -100.000000
In [64]:
ax = df.plot(kind='barh', sort_columns=True)
#Get the actual bars
bars = [item for item in ax.get_children() if isinstance(item, matplotlib.patches.Rectangle)]
bars = bars[:df.size]
#Reset the y positions for each bar
bars_y = [plt.getp(item, 'y') for item in bars]
for B, Y in zip(bars, np.flipud(np.array(bars_y).reshape(df.shape[::-1])).ravel()):
B.set_y(Y)
</code></pre>
<p><a href="https://i.stack.imgur.com/CkZ4r.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CkZ4r.png" alt="enter image description here"/></a></p>