如何使用Matplotlib 在子圖中繪製多個Seaborn聯合圖?


要繪製多個Seaborn聯合圖,我們可以使用jointplot()方法。

步驟

  • 向當前圖形新增一個子圖。

  • 使用某些鍵建立一個字典。

  • 使用Pandas建立一個數據幀。

  • 使用 jointplot()方法制作聯合圖。

  • 要繪製曲線,請使用plot()方法。

  • 要顯示圖形,請使用show()方法。

示例

from matplotlib import pyplot as plt
import pandas as pd
import seaborn as sns
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
plt.subplot()
d = {
   'y=1/x': [1 / i for i in range(1, 10)],
   'y=x': [i for i in range(1, 10)],
   'y=x^2': [i * i for i in range(1, 10)],
   'y=x^3': [i * i * i for i in range(1, 10)]
}
df = pd.DataFrame(d)
jg = sns.jointplot(data=df)
jg.plot(sns.scatterplot, sns.histplot)
plt.show()

輸出

更新於:09-Apr-2021

2K+閱讀

啟動你的 職業

完成本課程以獲得認證

開始
廣告