擅长:python、mysql、java
<p>我认为群和子群的联合错误顺序归结为一个单一的特征:如通常的图所示,<code>y</code>轴向上增加。尝试反转轴的<code>y</code>轴,就像在这个没有熊猫的示例中一样:</p>
<pre><code>import numpy as np
import matplotlib.pyplot as plt
x=range(5)
y=np.random.randn(5)
#plot1: bar
plt.figure()
plt.bar(x,y)
#plot2: barh, wrong order
plt.figure()
plt.barh(x,y)
#plot3: barh with correct order: top-down y axis
plt.figure()
plt.barh(x,y)
plt.gca().invert_yaxis()
</code></pre>
<p>特别是对于pandas,<code>pandas.DataFrame.plot</code>及其各种绘图子方法返回matplotlib axes对象,因此可以直接反转其y轴:</p>
<pre><code>ax = df.plot.barh() # or df.plot(), or similar
ax.invert_yaxis()
</code></pre>