Seaborn Destine()带回了ytick标签
下面是一段代码片段Seaborn Destine()带回了ytick标签,seaborn,Seaborn,下面是一段代码片段 tips = sns.load_dataset("tips") g = sns.FacetGrid(tips, col = 'time') g = g.map(plt.hist, "tip") 具有以下输出 我想在保持其余部分不变的情况下,为这些图引入鄙视偏移。因此,我在现有代码中插入了鄙视函数: tips = sns.load_dataset("tips") g = sns.FacetGrid(tips, col = 'time') g.despine(offset=1
tips = sns.load_dataset("tips")
g = sns.FacetGrid(tips, col = 'time')
g = g.map(plt.hist, "tip")
具有以下输出
我想在保持其余部分不变的情况下,为这些图引入鄙视偏移。因此,我在现有代码中插入了鄙视函数:
tips = sns.load_dataset("tips")
g = sns.FacetGrid(tips, col = 'time')
g.despine(offset=10)
g = g.map(plt.hist, "tip")
这将导致以下图表
因此,偏移将应用于轴。但是,右图上的ytick标签又回来了,我不想要
有人能帮我吗?要删除yaxis勾号标签,您可以使用以下代码: libs:
import seaborn as sns
sns.set_style('ticks')
调整后的代码:
tips = sns.load_dataset("tips")
g = sns.FacetGrid(tips, col = 'time')
g.despine(offset=10)
g = g.map(plt.hist, "tip")
# IMPORTANT: I assume that you use colwrap=None in FacetGrid constructor
# loop over the non-left axes:
for ax in g.axes[:, 1:].flat:
# get the yticklabels from the axis and set visibility to False
for label in ax.get_yticklabels():
label.set_visible(False)
ax.yaxis.offsetText.set_visible(False)
更一般一点,图像现在有一个2x2的FaceGrid,您想用偏移量来忽略它,但是x和yticklabels返回:
使用以下代码将其全部删除:
tips = sns.load_dataset("tips")
g = sns.FacetGrid(tips, col = 'time', row='sex')
g.despine(offset=10)
g = g.map(plt.hist, "tip")
# IMPORTANT: I assume that you use colwrap=None in FacetGrid constructor
# loop over the non-left axes:
for ax in g.axes[:, 1:].flat:
# get the yticklabels from the axis and set visibility to False
for label in ax.get_yticklabels():
label.set_visible(False)
ax.yaxis.offsetText.set_visible(False)
# loop over the top axes:
for ax in g.axes[:-1, :].flat:
# get the xticklabels from the axis and set visibility to False
for label in ax.get_xticklabels():
label.set_visible(False)
ax.xaxis.offsetText.set_visible(False)
更新:
为完整起见,mwaskom()解释了出现此问题的原因:
这是因为matplotlib在移动脊椎时在内部调用axis.reset_ticks()。否则,脊椎会移动,但蜱虫会停留在同一位置。它在matplotlib中是不可配置的,即使可以配置,我也不知道是否有用于移动单个刻度的公共API。不幸的是,我认为你将不得不删除剔标签后,抵消自己的刺