如何在 matplotlib 中使用 unicode 符號?


為了在 matplotlib 中使用 unicode 符號,我們可以採取以下步驟。

步驟

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

  • 使用帶有 unicode 符號的 text() 方法向影像新增文字。此處我們使用了 Unicode 字元 (Δ),其字元程式碼為 (0394)。

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

示例

import matplotlib.pyplot as plt

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

# Unicode symbol
plt.text(0.5, 0.5, s=u"\u0394", fontsize=50)

# Display the plot
plt.show()

輸出

它將產生以下輸出 −


現在,讓我們使用另一個 Unicode 字元 (\u2734)。

它將產生以下輸出 −

更新於: 09-Oct-2021

2K+ 瀏覽量

開啟你的職業生涯

完成課程獲得認證

開始
廣告
© . All rights reserved.