如何用 Matplotlib 在 Seaborn 折線圖上畫一條虛線?


要在 Seaborn 折線圖上畫一條虛線,我們可以在 lineplot() 方法的引數中使用 linestyle="dashed"

步驟

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

  • 使用 numpy 建立 xy 資料點。

  • lineplot() 方法的引數中使用 xy 資料點和 linestyle="dashed"

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

範例

import seaborn as sns
import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
x = np.random.rand(10)
y = np.random.rand(10)
ax = sns.lineplot(x=x, y=y, linestyle="dashed")
plt.show()

輸出

更新時間:2021 年 6 月 1 日

5,000+ 次瀏覽

開啟你的 職業

完成課程獲得認證

立刻開始
廣告