0

I have a data set similar to:

    Count          ID      size 
0   25             0001    1     
1   4              0001    2    
2   9              0001    3    
3   13             0001    4     
4   19             0001    5    
...          
8   11             0003    10           
9   10             0003    12              
10  7              0003    14              
11  15             0003    16 

To create categorized plots I use the following simple code:

import seaborn as sns
sns.catplot(data=df, x='size', y='Count', col='ID', kind='bar')

This gives a perfect result. However, currently I am exploring the possibilities for a much larger and diverse dataset. The problem with the catplot function is that it will use the same bins for all the plots.

The new dataset is more like:

    Count          ID      size 
0   25             0001    1     
1   4              0001    2    
2   9              0001    3    
3   13             0001    4     
4   19             0001    5    
...          
8   11             0003    100           
9   10             0003    150              
10  7              0003    200              
11  15             0003    250

Therefor, it is not relevant to have the same bins for all IDs. My objective is to create plots for each ID where the range of bins is depended on the largest and smallest size of the ID. Unfortunately, I have been unable to tackle this problem.

Thanks for the help in advance!

Maurice500
  • 21
  • 4

1 Answers1

0

Try using for loop. Example:

import seaborn as sns

for id in df["ID"].unique():
    sns.catplot(data=df.where(df["ID"] == id), x='size', y='Count', col='ID', kind='bar')

I believe there is more pythonic way, so wait a little bit for another answers.

Andrii Syd
  • 308
  • 5
  • 15