How to plot non-square Seaborn jointplot or JointGrid

后端 未结 3 1096
情话喂你
情话喂你 2020-12-20 13:44

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

相关标签:
3条回答
  • 2020-12-20 14:09

    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.

    0 讨论(0)
  • 2020-12-20 14:09

    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

    0 讨论(0)
  • 2020-12-20 14:13

    You will need to set the ylim and xlim parameters, which will limit the x and y axis to the tuple ranges you specify:

    e.g.

    sns.jointplot(x="n_estimators", y="learning_rate", data=data,
                  color="#172235", height=8, ratio=10, space=0,
                  ylim=(0, 1.1), xlim=(-20, 310))  # <-- this
    
    
    0 讨论(0)
提交回复
热议问题