set individual ylim of seaborn lmplot columns

2020-05-06 10:24发布

I've made a lmplot column plot (subplot) using the following commands:

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

The FacetGrid seems to set the ylim of all subplots to the maximum value in all of the data. I would like to set the ylim individually for each subplot. I first looked to the answer of this question:

How to set some xlim and ylim in Seaborn lmplot facetgrid

I tested:

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

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

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

However, this method also seems to give the same ylim for all subplots. Maybe I'm not accessing the right axis? I'd really appreciate some help.

1条回答
一夜七次
2楼-- · 2020-05-06 11:05

If you want to be able to alter the ylim of one particular plot in the FacetGrid you have to explicitly create it with g = sns.lmplot(..., sharey=False)

example:

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

查看更多
登录 后发表回答