如何為 Seaborn lmplot 新增標題?


要為 Seaborn Implot 新增標題,我們可以採取以下步驟:-

  • 設定圖形大小並調整子圖之間及周圍的填充。
  • 建立一個包含兩列(X 軸和 Y 軸)的 Pandas 資料框
  • 使用implot() 方法。
  • 使用gca() 方法獲取當前軸。
  • 使用show() 方法顯示圖形。

示例

import pandas
import matplotlib.pylab as plt
import seaborn as sns
import numpy as np

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

df = pandas.DataFrame({"X-Axis": [np.random.randint(10) for i in range(10)], "Y-Axis": [i for i in range(10)]})

bar_plot = sns.lmplot(x='X-Axis', y='Y-Axis', data=df, height=3.5)

ax = plt.gca()

ax.set_title("Random Data Implot")

plt.show()

輸出

更新時間:2021 年 6 月 5 日

927 次瀏覽

開啟你的職業生涯

完成課程認證

開始吧
廣告
© . All rights reserved.