如何绘制非方形Seaborn关节图或JointGrid [英] How to plot non-square Seaborn jointplot or JointGrid

查看:269
本文介绍了如何绘制非方形Seaborn关节图或JointGrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Seaborn的JointGrid绘制非对称数据.我可以使它使用相等的长宽比,但是然后我有多余的空格:

I am trying to plot my non-symmetric data using Seaborn's JointGrid. I can get it to use an equal aspect ratio, but then I have unwanted whitespace:

如何删除填充物? jointplot

How do you remove the padding? The documentation for both jointplot and JointGrid simply say

大小:数字,可选

size : numeric, optional

图形的大小(它将是正方形).

Size of the figure (it will be square).

我还尝试将extent kwarg馈送给jointplot和JointGrid以及ylim都没有运气.

I also tried going into feeding the extent kwarg to both jointplot and JointGrid, as well as ylim with no luck.

import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
x = np.random.normal(0.0, 10.0, 1000)
y = np.random.normal(0.0, 1.0, 1000)
joint = sns.jointplot(x, y)
joint.plot_marginals(sns.distplot, kde=False)
joint.ax_joint.set_aspect('equal')  # equal aspect ratio
plt.show() 

推荐答案

偶然发现了这个问题,自己寻找答案.弄清楚了之后,我想我应该发布解决方案了.由于jointplot代码似乎非常坚持要使图形平方,所以我不知道这是否被认为是不正确的做法,但是无论如何...

Stumbled upon this question looking for the answer myself. Having figured it out I thought I'd post the solution. As the jointplot code seems quite insistent on having the figure square I don't know if this is considered bad practice, but anyhow...

如果我们浏览jointplot代码并将其跟随到JointGrid中,则在以下表达式中使用jointplotsize参数(同样是JointGrid):

If we look through the jointplot code and follow it into JointGrid, the size parameter to jointplot (and equally JointGrid) is used in the following expression:

f = plt.figure(figsize=(size, size))
# ... later on
self.fig = f

因此,要获得非正方形的JointGrid图,只需运行:

So to get a non-square JointGrid plot, simply run:

grid = sns.jointplot(...)
grid.fig.set_figwidth(6)
grid.fig.set_figheight(4)
grid.savefig("filename.png", dpi=300)

用于6x4图形.

这篇关于如何绘制非方形Seaborn关节图或JointGrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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