【问题标题】:Is it possible to do a "zoom inset" using seaborn?是否可以使用 seaborn 进行“缩放插图”?
【发布时间】:2019-02-09 03:47:55
【问题描述】:

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 范围。 (如果需要,我也可以将图例移出,但这不是重点)

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

【问题讨论】:

  • 是的,您可以完全按照您发布的链接中显示的内容进行操作,该链接当然 使用 matplotlib,但可以与 seaborn 中制作的图进行交互
  • matplotlib 还有一个“zoomed_inset”功能,您也可以将其与 seaborn 一起使用。 matplotlib 示例 - matplotlib.org/examples/axes_grid/inset_locator_demo2.html

标签: python-3.x matplotlib seaborn insets


【解决方案1】:

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.])

【讨论】:

  • 您能否提供一个工作示例 - 这会更有用。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-27
  • 2013-01-25
  • 1970-01-01
  • 2019-08-12
相关资源
最近更新 更多