Rafael Higa
Rafael Higa

Reputation: 725

Histogram given y axis

I know that plt.hist() method needs x-axis as argument to be plotted. But I have the following situation:

id   cluster_number
 1               10
 2               21
 3               55
 4               36
 5               70
 .                .
 .                .
 .                .

if I use my_serie = df.groupby('cluster_number')['id'].size(), the output would be a Serie with the number of id's in each cluster.

Then, with plt.plot(my_serie), I get a plot with:

Of course, this type of data would fit better in a histogram. But plt.hist() will understand the serie given as input as an x-axis values, not y-axis values, as understood by plt.plot():

How can I get a histogram with x-axis and y-axis arrangement equal to plt.plot()?

Upvotes: 2

Views: 181

Answers (1)

Quang Hoang
Quang Hoang

Reputation: 150825

Wouldn't this be a bar plot:

my_serie = df.groupby('cluster_number')['id'].size()
my_serie.plot.bar()

Upvotes: 1

Related Questions