简体   繁体   中英

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:

  • x-axis : number of clusters...
  • y-axis : with a given number of id's

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() :

  • x-axis : number of id's in a cluster...
  • y-axis : and number of clusters with that number of id's read in x-axis

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

Wouldn't this be a bar plot:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM