如何更改 Matplotlib 顏色條標籤的字型屬性?


要更改 matplotlib 顏色條標籤的字型屬性,我們可以採取以下步驟:

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

  • 使用 numpy 建立x、yz資料點。

  • 使用imshow()方法將資料顯示為影像,即,在 2D 正則光柵上。

  • 為 ScalarMappable 例項*mappable*建立colorbar

  • 使用 **colorbar** 軸,設定字型屬性,使標籤加粗。

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

示例

import numpy as np
import matplotlib.pyplot as plt

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

x, y = np.mgrid[-1:1:100j, -1:1:100j]
z = (x + y) * np.exp(-5.0 * (x ** 2 + y ** 2))

plt.imshow(z, extent=[-1, 1, -1, 1])

cb = plt.colorbar
cb.set_label(label='my color bar label', weight='bold')

plt.show()

輸出

更新於:04-06-2021

3K+ 瀏覽

職業生涯起航

完成課程獲得認證

立即開始
廣告
© . All rights reserved.