Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 536
mrmagicfluffyman Avatar asked Jul 17 '16 18:07

mrmagicfluffyman


People also ask

How do you set limits on the y axis?

Set y-Axis Limits for Specific Axes Call the tiledlayout function to create a 2-by-1 tiled chart layout. Call the nexttile function to create the axes objects ax1 and ax2 . Plot data into each axes. Then set the y-axis limits for the bottom plot by specifying ax2 as the first input argument to ylim .

How do you change the Y axis on a histogram in Python?

The ylim() function is used to set or to get the y-axis limits or we can say y-axis range. By default, matplotlib automatically chooses the range of y-axis limits to plot the data on the graph area. But if we want to change that range of the current axes then we can use the ylim() function.

How do you change the Y axis on a histogram?

Divide the data into intervals — see Number of Bins in a Histogram. Count the number of data points in each interval. Divide the counts by the total number of data points. Divide that result by the interval width as shown on the x axis, to obtain the height of the bar along the y axis.


1 Answers

If you use

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

it should work.

like image 187
WilliamEllisWebb Avatar answered Sep 28 '22 07:09

WilliamEllisWebb