如何在 Seaborn 中繪製非正方形的聯合圖或聯合網格? (Matplotlib)
要繪製非正方形的 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()輸出

廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP