是否可以使用 seaborn 执行 "zoom inset"?

Is it possible to do a "zoom inset" using seaborn?

来自 matplotlib 的

This example 展示了如何进行插图。但是我正在使用 seaborn,特别是 kdeplot。

sns.kdeplot(y, label='default bw')
sns.kdeplot(y, bw=0.5, label="bw: 0.2", alpha=0.6)
sns.kdeplot(y, linestyle="--", bw=2, label="bw: 2", alpha=0.6)
sns.kdeplot(y, linestyle=":", bw=5, label="bw: 5", alpha=0.6)

碰巧我在图表的右侧有很多空白 space,我想在那里放一个放大的插图以阐明较低的 x 范围。 (如果需要,我也可以将图例移出,但这不是重点)

是否可以单独使用 seaborn 来做到这一点,还是我必须放弃 seaborn 的便利性并将绘图转换为 matplotlib?

seaborn 只是 matplotlib 的包装器,您不必二选一。在你的情况下,you can instruct sns.distplot() to use whathever Axes object you want using the ax= parameter

因此:

fig, ax = plt.subplots()
sns.distplot(d, ax=ax)

ax2 = plt.axes([0.2, 0.6, .2, .2], facecolor='y')
sns.distplot(d, ax=ax2)
ax2.set_title('zoom')
ax2.set_xlim([0.9,1.])