如何绘制非正方形的 Seaborn 联合图或联合网格?(Matplotlib)
matplotlibpythondata visualization更新于 2025/7/11 2:52:17
要绘制非正方形的 Seaborn 联合图或联合网格,我们可以使用 set_figwidth() 和 set_figheight() 方法。
步骤
- 设置图形大小并调整子图之间和周围的填充。
- 使用 numpy 创建 x 和 y 数据点。
- 创建一个有两列的数据框。
- 使用 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()
输出

相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

