Home > Software design >  python plt barh does cannot properly display the bars
python plt barh does cannot properly display the bars

Time:12-27

I have problems when drawing horizontal bar chart firstly if we draw it in plt.bar

plt.figure(figsize=(8,5))
plt.bar(range_df.range_start, range_df.cum_trade_vol, width=30)
plt.show()

enter image description here

but if we draw it in plt.barh

plt.figure(figsize=(8, 5))
plt.barh(range_df.range_start, range_df.cum_trade_vol)
plt.show()

its either enter image description here

or like:

enter image description here

The problem, I think, is because the crowded data that left too few gaps. What can we do to properly draw the graph? (since we cannot set width with barh? or can we?) Maybe another plot package?

Please do not reset the y axis value as the current value is important

The data can be downloaded at https://drive.google.com/file/d/1y8fHazEFhVR_u2KL6uUsBqv0qmXOd2xT/view?usp=share_link

the notebook is at:

https://colab.research.google.com/drive/1MbjJE4B-mspDRqCYXnDf8hyFRK_uLmRp?usp=sharing

Thank you

CodePudding user response:

I am somewhat unsure of what you are talking about. When writing the horizontal plot, you drop width parameter. There is an equivalent version for plt.barh which is height. So try

plt.barh(range_df.range_start, range_df.cum_trade_vol, height=30)
  • Related