Con*_*ino 10 python facet seaborn
我正在尝试将每个方面的x轴限制设置为Seaborn facetgrid distplot的不同值.我知道我可以通过g.axes访问子图中的所有轴,所以我试图迭代它们并设置xlim:
g = sns.FacetGrid(mapping, col=options.facetCol, row=options.facetRow, col_order=sorted(cols), hue=options.group)
g = g.map(sns.distplot, options.axis)
for i, ax in enumerate(g.axes.flat): # set every-other axis for testing purposes
if i % 2 == 0[enter link description here][1]:
ax.set_xlim(-400,500)
else:
ax.set_xlim(-200,200)
Run Code Online (Sandbox Code Playgroud)
但是,当我这样做时,所有轴都设置为(-200,200)而不是每个其他方面.
我究竟做错了什么?
Con*_*ino 14
mwaskom有解决方案; 在此处发布完整性 - 只需将以下行更改为:
g = sns.FacetGrid(mapping, col=options.facetCol, row=options.facetRow, col_order=sorted(cols), hue=options.group, sharex=False)
Run Code Online (Sandbox Code Playgroud)
正如mwaskom所建议的,您可以简单地使用FacetGrid(sharex分别sharey)来允许绘图具有独立的轴刻度:
\n\nshare{x,y} : bool, \xe2\x80\x98col\xe2\x80\x99 或 \xe2\x80\x98row\xe2\x80\x99 可选
\n如果为 true,则构面将跨列共享 y 轴和/或跨行共享 x 轴。
\n
例如,与:
\nsharex=False每个图都有自己的轴sharex=\'col\'每列都有自己的轴sharex=\'row\'每一行都有自己的轴(即使这对我来说没有多大意义)sns.FacetGrid(data, ..., sharex=\'col\')\nRun Code Online (Sandbox Code Playgroud)\n如果您间接使用 FacetGrid,例如通过displot或relplot,则必须使用facet_kws关键字参数:
sns.displot(data, ..., facet_kws={\'sharex\': \'col\'})\nRun Code Online (Sandbox Code Playgroud)\n