gpt4 book ai didi

python-3.x - 是否可以使用 seaborn 执行 "zoom inset"?

转载 作者:行者123 更新时间:2023-12-04 00:04:15 24 4
gpt4 key购买 nike

This example来自 matplotlib 显示了如何进行插入。但是我正在使用 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)

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

enter image description here

是否可以单独使用 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.])

enter image description here

关于python-3.x - 是否可以使用 seaborn 执行 "zoom inset"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52160719/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com