是否可以进行“缩放插入"?使用seaborn? [英] Is it possible to do a "zoom inset" using seaborn?

查看:44
本文介绍了是否可以进行“缩放插入"?使用seaborn?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

seaborn 只是 matplotlib 的包装器,您不必选择其中之一.在您的情况下,

This example from matplotlib shows how to do an inset. However I am working with seaborn, specifically the 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)

It so happens that I have a lot of empty space on the right side of the graph and I would like to put a zoomed in inset there to clarify the lower x range. (If need be I could move the legend out as well, but that's besides the point)

Is it possible to do that with seaborn alone or do I have to forego the convenience of seaborn and convert the plots to matplotlib?

解决方案

seaborn is just a wrapper around matplotlib, you do not have to chose one or the other. In your case, you can instruct sns.distplot() to use whathever Axes object you want using the ax= parameter

Therefore:

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

这篇关于是否可以进行“缩放插入"?使用seaborn?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆