如何使用 Seaborn 在同一個圖表上繪製兩個小提琴圖系列?


要使用 Seaborn 在同一圖表上繪製兩個小提琴圖系列,我們可以執行以下步驟。

步驟

  • 設定圖形大小並調整子圖之間和周圍的邊距。

  • 從線上儲存庫載入示例資料集(需要網際網路)。

  • 使用 violinplot() 方法建立一個小提琴圖。

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

示例

# Import Seaborn and Matplotlib
import seaborn as sns
from matplotlib import pyplot as plt

# Set the figure size
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True

# Load an example dataset
tips = sns.load_dataset("tips")

# Create a violin plot using Seaborn
sns.violinplot(x="day", y="total_bill", hue="time", data=tips)

# Display the plot
plt.show()

輸出

將生成以下輸出 −

更新於:2021-10-08

1K+ 瀏覽量

開啟您的 職業生涯

完成課程,獲得認證

開始
廣告
© . All rights reserved.