How to scale the y-axis of a ship with boom clearance?

I am using factorplot(kind="bar") .

How to scale the y axis, for example, using a logarithmic scale?

I tried to work with the plot axes, but it somehow ruined the tablet, so first try your solution to make sure that it really works.

+17
python seaborn
source share
3 answers

You can use the Matplotlib commands after calling factorplot . For example:

 import seaborn as sns import matplotlib.pyplot as plt sns.set(style="whitegrid") titanic = sns.load_dataset("titanic") g = sns.factorplot("class", "survived", "sex", data=titanic, kind="bar", size=6, palette="muted", legend=False) g.fig.get_axes()[0].set_yscale('log') plt.show() 

enter image description here

+13
source share

Given your question mentioning barplot , I thought I would add a solution for this type of chart as well, since it differs from factorplot in the @Jules solution.

 import seaborn as sns import matplotlib.pyplot as plt sns.set(style="whitegrid") titanic = sns.load_dataset("titanic") g = sns.barplot(x="class", y="survived", hue="sex", data=titanic, palette="muted") g.set_yscale("log") 

enter image description here

+13
source share

If you encounter the problem of bars disappearing when setting up the logarithmic scale using the previous solutions, try adding log=True to the call to the sea gateway function instead. (I don't have enough reputation to comment on other answers).

Using sns.factorplot :

 import seaborn as sns import matplotlib.pyplot as plt sns.set(style="whitegrid") titanic = sns.load_dataset("titanic") g = sns.factorplot(x="class", y="survived", hue="sex", kind='bar', data=titanic, palette="muted", log=True) g.ax.set_ylim(0.05, 1) 

Using sns.barplot :

 import seaborn as sns import matplotlib.pyplot as plt sns.set(style="whitegrid") titanic = sns.load_dataset("titanic") g = sns.barplot(x="class", y="survived", hue="sex", data=titanic, palette="muted", log=True) g.set_ylim(0.05, 1) 
+5
source share

All Articles