How to plot non-square Seaborn jointplot or JointGrid

别等时光非礼了梦想. 提交于 2019-11-28 07:16:03

问题


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:

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

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() 

回答1:


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

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

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)

for a 6x4 figure.




回答2:


For those who use Seaborn into a Jupyter Notebook, I suggest calling set_figwidht() and set_figheight() just after the sns.jointplot() command.

my_plot=sns.jointplot(x="K",y="errori",data=risultati , kind="scatter")
my_plot.fig.set_figwidth(13)

Jupyter Example



来源:https://stackoverflow.com/questions/29909515/how-to-plot-non-square-seaborn-jointplot-or-jointgrid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!