python barh_Matplotlib,水平条形图(barh)颠倒

我将认为这是一个错误,即条的y位置分配不正确。不过,修补程序相对简单:

这只是一个正确的顺序,那叫做…,正确的顺序。任何不正确的命令,都是错误的命令。:p页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)

python barh_Matplotlib,水平条形图(barh)颠倒

Original: https://blog.csdn.net/weixin_39527078/article/details/113479162
Author: weixin_39527078
Title: python barh_Matplotlib,水平条形图(barh)颠倒

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/768869/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球