如何顯示 Seaborn pairplot() 或 PridGrid() 圖表的標題?(Matplotlib)


若要顯示 Seaborn pairplot() 的圖表標題,我們可以使用 pp.fig.suptitle() 方法。

步驟

  • 設定圖形大小並調整子圖之間和周圍的邊距。
  • 建立一個 Pandas 資料框,即一個二維、大小可變、潛在異構的表格資料。
  • 繪製資料集中的成對關係。
  • 將居中標題新增到圖形。
  • 要顯示圖形,請使用 show() 方法。

示例

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

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

df = pd.DataFrame(np.random.random((5, 5)),
                  columns=["a", "b", "c", "d", "e"])

pp = sns.pairplot(df, height=3.5)
pp.fig.suptitle("My Pairplot")

plt.show()

輸出

更新於: 2021 年 6 月 18 日

2000+ 瀏覽量

開啟您的 職業生涯

完成課程以獲取認證

開始
廣告
© . All rights reserved.