Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python seaborn catplot - How do I change the y-axis scale to percentage

In the figure the y-axis labels are in decimals from (0 to 1) i.e (0.1, 0.2, 0.4 etc). How can I convert this into a % format (10%, 20%, 40% etc). Just 10, 20, 40 also will do.

Thanks, John

g = sns.catplot(x="who", y="survived", col="class",
...                 data=titanic, saturation=.5,
...                 kind="bar", ci=None, aspect=.6)
like image 895
John Mathew Avatar asked Sep 26 '18 07:09

John Mathew


People also ask

How to set the range of Y-axis for a seaborn boxplot using matplotlib?

How to set the range of Y-axis for a Seaborn boxplot using Matplotlib? Using set_style () method, set the aesthetic style of the plots. Load the dataset using load_dataset ("tips"); need Internet. Using boxplot (), draw a box plot to show distributions with respect to categories. To set the range of Y-axis, use the ylim () method.

How to label and change the scale of a seaborn kdeplot?

How to label and change the scale of a Seaborn kdeplot's axes? (Matplotlib) Set the figure size and adjust the padding between and around the subplots. Create random data points using numpy. Plot Kernel Density Estimate (KDE) using kdeplot () method.

What is the syntax of Seaborn catplot?

It is built on top of Matplotlib, another vast and deep data visualization library. Syntax: seaborn.catplot (*, x=None, y=None, hue=None, data=None, row=None, col=None, kind=’strip’, color=Non e, palette=None, **kwargs)

How do I change the range of the Y-axis of a scatter plot?

To create a scatter plot, we use the scatter () function of the pyplot module, and to set the range of the y-axis we use the ylim () function. Here we’ll discuss how we can change the y-axis limit of the specific subplot if we draw multiple plots in a figure area.


1 Answers

You may use a PercentFormatter on the axes of the grid.

import seaborn as sns
import matplotlib.pyplot as plt
from  matplotlib.ticker import PercentFormatter
titanic = sns.load_dataset("titanic")

g = sns.catplot(x="who", y="survived", col="class",
                 data=titanic, saturation=.5,
                 kind="bar", ci=None, aspect=.6)

for ax in g.axes.flat:
    ax.yaxis.set_major_formatter(PercentFormatter(1))
plt.show()

enter image description here

like image 137
ImportanceOfBeingErnest Avatar answered Nov 03 '22 02:11

ImportanceOfBeingErnest