Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the number or rows and columns in my seaborn catplot

I have a dataframe that looks like this: dataframe:

with several different model_names's. I am trying to graph the data in a seaborn catplot using the following code:

sns.set(style="whitegrid")
sns.catplot(x='model_name', y='score', hue='train_val_test', col='score_name',
            data=classification_scores, kind='bar', height=4, aspect=.8)

The follow is the graph that I result in:graph

How do I change the format so the graphs are displayed on a 2x2 grid? Having them all in one line is too cramped.

like image 920
tshwizz Avatar asked Jul 23 '20 18:07

tshwizz


People also ask

What is Factorplot in Seaborn?

Factor Plot is used to draw a different types of categorical plot . The default plot that is shown is a point plot, but we can plot other seaborn categorical plots by using of kind parameter, like box plots, violin plots, bar plots, or strip plots.

How to plot categorical plots in Seaborn?

Plotting categorical plots it is very easy in seaborn. In this example x,y and hue take the names of the features in your data. Hue parameters encode the points with different colors with respect to the target variable. For the count plot, we set a kind parameter to count and feed in the data using data parameters.

How do you count observations in Seaborn?

Seaborn count plot As the name suggests, a count plot displays the number of observations in each category of your variable. Throughout this article, we will be using catplot () function changing its kind parameter to create different plots. For the count plot, we set kind parameter to count and feed in the data using data parameter.

Can you change the color of a seaborn line plot?

Changing the line types of a Seaborn line plot may be important if we are to print the plots in black and white as it makes it easier to distinguish the different lines from each other. In this example, we are going to build on the earlier examples and change the color of the Seaborn line plot.

What is Seaborn in Python?

Seaborn is a Python data visualization library based on matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics. Seaborn helps resolve the two major problems faced by Matplotlib; the problems are?


1 Answers

Use the parameter col_wrap or row_wrap to set a desired number of columns/rows. I.e.

sns.catplot(
    x='model_name',
    y='score',
    hue='train_val_test',
    col='score_name',
    col_wrap=3, #Set the number of columns you want.
    data=classification_scores,
    kind='bar',
    height=4,
    aspect=.8
)

For 3 columns. Similarly, if one uses row for categorization, the respective variable is called row_wrap.

like image 180
Đorđe Relić Avatar answered Nov 03 '22 08:11

Đorđe Relić