如何用条形图来衡量Seaborn的y轴?

时间:2021-08-14 12:47:50

I'm using factorplot(kind="bar").

我用factorplot(类型=“酒吧”)。

How do I scale the y-axis, for example with log-scale?

如何缩放y轴,例如对数尺度?

I tried tinkering with the plot's axes, but that always messed up the bar plot in one way or another, so please try your solution first to make sure it really works.

我试着修改这个图的坐标轴,但这总是会以这样或那样的方式打乱这个图,所以请先尝试一下你的解决方案,以确保它确实有效。

3 个解决方案

#1


9  

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

您可以在调用factorplot之后使用Matplotlib命令。例如:

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

如何用条形图来衡量Seaborn的y轴?

#2


4  

Considering your question mentions barplot I thought I would add in a solution for that type of plot also as it differs from the factorplot above.

考虑到你的问题提到了barplot,我想我应该为这种类型的plot添加一个解决方案,因为它与上面的factorplot不同。

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')

如何用条形图来衡量Seaborn的y轴?

#3


0  

If you are facing the problem of vanishing bars upon setting log-scale using the previous solutions, try adding log=True to the seaborn function call instead. (I'm lacking reputation to comment on the other answers).

如果您在使用前面的解决方案设置日志级别时遇到了消失条的问题,可以尝试在seaborn函数调用中添加日志=True。(我对其他答案没有什么可评论的。)

Using sns.factorplot:

使用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:

使用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)

#1


9  

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

您可以在调用factorplot之后使用Matplotlib命令。例如:

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

如何用条形图来衡量Seaborn的y轴?

#2


4  

Considering your question mentions barplot I thought I would add in a solution for that type of plot also as it differs from the factorplot above.

考虑到你的问题提到了barplot,我想我应该为这种类型的plot添加一个解决方案,因为它与上面的factorplot不同。

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')

如何用条形图来衡量Seaborn的y轴?

#3


0  

If you are facing the problem of vanishing bars upon setting log-scale using the previous solutions, try adding log=True to the seaborn function call instead. (I'm lacking reputation to comment on the other answers).

如果您在使用前面的解决方案设置日志级别时遇到了消失条的问题,可以尝试在seaborn函数调用中添加日志=True。(我对其他答案没有什么可评论的。)

Using sns.factorplot:

使用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:

使用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)