如何绘制非方形Seaborn关节图或JointGrid

编程入门 行业动态 更新时间:2024-10-24 13:22:33
本文介绍了如何绘制非方形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 和 JointGrid 简单地说

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中,则在以下表达式中使用jointplot的size参数(同样是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

本文发布于:2023-11-30 20:17:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1651355.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方形   关节   Seaborn   JointGrid

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!