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.
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 .
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.
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.
If you use
data['ranking'].plot.hist(ylim=(0,1))
it should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With