更改 y 轴刻度 - FacetGrid
Change y-axis scale - FacetGrid
我不知道如何更改 y 轴的比例。我的代码是:
grid = sns.catplot(x='Nationality', y='count',
row='Age', col='Gender',
hue='Type',
data=dfNorthumbria2, kind='bar', ci='No')
我只想增加完整数字而不是 .5
更新
我刚刚发现这个 tutorial 可能最简单的解决方案如下:
grid.set(yticks=list(range(5)))
来自 grid.set
的帮助
Help on method set in module seaborn.axisgrid:
set(**kwargs) method of seaborn.axisgrid.FacetGrid instance
Set attributes on each subplot Axes.
由于 seaborn 是建立在 matplotlib 之上的,您可以使用 plt 中的 yticks
import matplotlib.pyplot as plt
plt.yticks(range(5))
然而,这只改变了我的模型示例中上一行的 yticks。
出于这个原因,您可能希望根据带有 ax.set_yticks()
的轴更改 y 刻度。要从 grid
对象获取轴,您可以按如下方式实现列表理解:
[ax[0].set_yticks(range(0,150,5) )for ax in grid.axes]
一个完整的可复制示例如下所示(改编自 here)
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="ticks")
exercise = sns.load_dataset("exercise")
grid = sns.catplot(x="time", y="pulse", hue="kind",
row="diet", data=exercise)
# plt.yticks(range(0,150,5)) # Changed only one y-axis
# Changed y-ticks to steps of 20
[ax[0].set_yticks(range(0,150,20) )for ax in grid.axes]
我不知道如何更改 y 轴的比例。我的代码是:
grid = sns.catplot(x='Nationality', y='count',
row='Age', col='Gender',
hue='Type',
data=dfNorthumbria2, kind='bar', ci='No')
我只想增加完整数字而不是 .5
更新
我刚刚发现这个 tutorial 可能最简单的解决方案如下:
grid.set(yticks=list(range(5)))
来自 grid.set
Help on method set in module seaborn.axisgrid:
set(**kwargs) method of seaborn.axisgrid.FacetGrid instance
Set attributes on each subplot Axes.
由于 seaborn 是建立在 matplotlib 之上的,您可以使用 plt 中的 yticks
import matplotlib.pyplot as plt
plt.yticks(range(5))
然而,这只改变了我的模型示例中上一行的 yticks。
出于这个原因,您可能希望根据带有 ax.set_yticks()
的轴更改 y 刻度。要从 grid
对象获取轴,您可以按如下方式实现列表理解:
[ax[0].set_yticks(range(0,150,5) )for ax in grid.axes]
一个完整的可复制示例如下所示(改编自 here)
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="ticks")
exercise = sns.load_dataset("exercise")
grid = sns.catplot(x="time", y="pulse", hue="kind",
row="diet", data=exercise)
# plt.yticks(range(0,150,5)) # Changed only one y-axis
# Changed y-ticks to steps of 20
[ax[0].set_yticks(range(0,150,20) )for ax in grid.axes]