如何绘制非正方形的 Seaborn jointplot 或 JointGrid?(Matplotlib)

如何绘制非正方形的 Seaborn jointplot 或 JointGrid?(Matplotlib)

要绘制非正方形的 Seaborn jointplot 或 JointGrid,我们可以使用 set_figwidth()set_figheight() 方法。

步骤

  • 设置图像大小并调整子图之间和周围的填充。
  • 使用 numpy 创建 xy 数据点。
  • 创建一个具有两列的数据框。
  • 使用 jointplot() 方法绘制 jointplot。
  • 为使其非正方形,我们可以设置图形的宽度和高度。
  • 使用 show() 方法显示图像。

例子

import seaborn as sns
import numpy as np
from matplotlib import pyplot as plt
import pandas as pd

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

X = np.random.randn(1000,)
Y = 0.2 * np.random.randn(1000) + 0.5

df = pd.DataFrame(dict(x=X, y=Y))

jp = sns.jointplot(x="x", y="y", data=df, height=3.5,
                    joint_kws={'color': 'red'})
jp.fig.set_figwidth(7.50)
jp.fig.set_figheight(3.50)

plt.show()

输出

如何绘制非正方形的 Seaborn jointplot 或 JointGrid?(Matplotlib)

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程