Skip to content
Advertisement

How to change y-axis limits on a bar graph?

I have a df, from which Ive indexed europe_n and Ive plotted a bar plot.

  • europe_n (r=5, c=45), looks like this. ;
    enter image description here

  • df['Country'](string) & df['Population'](numeric) variable/s.

JavaScript

Which gives me;

enter image description here

Objective: Im trying to change my y-axis limit to start from 0, instead of 43,094.
I ran the, plt.ylim(0,500000) method, but there was no change to the y-axis and threw an error. Any suggestions from matplotlib library?

Error; enter image description here

Conclusion: The reason why I wasn’t able to plot the graph as I wanted was due to all columns being in object dtype. I only realized this when Jupyter threw an error stating, ‘there are no integers to plot’. Eventually converted the digit column Population to int type, code worked and I got the graph!

Advertisement

Answer

ax.set_ylim([0,max_value])

JavaScript
JavaScript

enter image description here





Be sure that you already imported the following packages,

JavaScript

Your code should probably like:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement