修改圖例中標籤的某一部分的樣式,我們可以採取以下步驟


若要修改圖例中標籤的某一部分的樣式,我們可以採取以下步驟 −

  • 使用 numpy 建立 **x** 的資料點。

  • 使用 **np.sin(x)** 繪製正弦曲線,並帶有文字標籤。

  • 使用 **np.cos(x)** 繪製餘弦曲線,並帶有文字標籤。

  • 要將圖例置於圖表上,請使用 **legend()** 方法。

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

示例

import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
x = np.linspace(-1, 1, 10)
plt.plot(x, np.sin(x), label="This is $\it{a\ sine\ curve}$")
plt.plot(x, np.cos(x), label="This is $\bf{a\ cosine\ curve}$")
plt.legend(loc='lower right')
plt.show()

輸出

更新日期:06-05-2021

192 次瀏覽

開啟你的 職業生涯

完成課程取得認證

開始吧
廣告