[英]Change y-axis scale - FacetGrid
I just now found this tutorial the probably easiest solution will be the following:我刚刚发现本教程可能最简单的解决方案如下:
grid.set(yticks=list(range(5)))
From the help of grid.set
在
grid.set
的帮助下
Help on method set in module seaborn.axisgrid:
set(**kwargs) method of seaborn.axisgrid.FacetGrid instance
Set attributes on each subplot Axes.
import matplotlib.pyplot as plt plt.yticks(range(5))
However this changed only the yticks of the upper row in my mockup example.然而,这仅改变了我的模型示例中上排的 yticks。
For this reason you probably want to change the y ticks based on the axis with ax.set_yticks()
.出于这个原因,您可能希望使用
ax.set_yticks()
更改基于轴的 y 刻度。 To get the axis from your grid
object you can implemented a list comprehension as follows:要从
grid
object 中获取轴,您可以实现列表理解,如下所示:
[ax[0].set_yticks(range(0,150,5) )for ax in grid.axes]
A full replicable example would look like this (adapted from 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]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.