设置seaborn lmplot列的个别ylim

问题描述 投票:0回答:1

我使用以下命令制作了一个lmplot列图(subplot):

g = sns.lmplot(x=COX, y='dX', data=tidy_data, hue='hue', col='comp', 
col_wrap=8, fit_reg=True, scatter=True, aspect=1.5,
            legend_out=True, truncate=True, scatter_kws={"s": 200})

figure of the plotted lmplot FacetGrid

FacetGrid似乎将所有子图的ylim设置为所有数据中的最大值。我想为每个子图单独设置ylim。我首先看了这个问题的答案:

How to set some xlim and ylim in Seaborn lmplot facetgrid

我测试过:

g.axes.shape
>>> (23, )

g.axes[0]
>>> AxesSubplot(0.0189366,0.704381;0.116079x0.258196)

g.axes[0].set_ylim(0, 1)
>>> 

然而,这种方法似乎也为所有子图提供了相同的ylim。也许我没有访问正确的轴?我真的很感激一些帮助。

python pandas matplotlib seaborn
1个回答
1
投票

如果你想能够改变FacetGrid中某个特定图的ylim,你必须用g = sns.lmplot(..., sharey=False)明确地创建它。

例:

tips = sns.load_dataset("tips")
g = sns.lmplot(x="total_bill", y="tip", col="day", hue="day", data=tips, col_wrap=2, size=3, 
               sharey=False)
g.axes[0].set_ylim((0,100))

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.