Search code examples
pandasmatplotlibhistogram

Set y axis limit in Pandas histogram


I am using Pandas histogram.

I would like to set the y-axis range of the plot.

Here is the context:

import matplotlib.pyplot as plt
%matplotlib inline

interesting_columns = ['Level', 'Group']

for column in interesting_columns:
    data['ranking'].hist(by=data[column], normed=True)

There is a range argument that can filter x-values, but I am unaware of the y equivalent:

hist(by=[column], normed=True, range=[0, 1]) #working argument
hist(by=[column], normed=True, y_range=[0, 1]) #hypothetical argument

I've read a lot of different methods for changing plot ranges using plt attributes. They do not seem to work in a loop and for subplots.

I am struggling to grasp the right way to approach this problem.


Solution

  • If you use

    data['ranking'].plot.hist(ylim=(0,1)) 
    

    (mind the .plot in the syntax!) it should work.