如何在 matplotlib 中生成未關聯繪圖的色條?


要在 matplotlib 中生成未關聯繪圖的色條,我們可以採取以下步驟。

步驟

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

  • 建立一個圖形和一組子圖。

  • 調整子圖佈局引數。

  • 按原樣規範四元數。返回四元數的範數

  • 獲取帶基本色條和水平方向的色條例項(cb)

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

示例

import matplotlib.pyplot as plt
import matplotlib as mpl

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

# Create a figure and a set of subplots
fig, ax = plt.subplots()

# Adjust the subplot layout parameter
fig.subplots_adjust(bottom=0.5)

# Normalize
norm = mpl.colors.Normalize(vmin=5, vmax=10)

# Get the colorbar instance
cb = mpl.colorbar.ColorbarBase(ax, cmap=mpl.cm.cool, norm=norm, orientation='horizontal')

# Display the plot
plt.show()

輸出

它將生成以下輸出 −

更新於: 19-Oct-2021

118 次瀏覽

開啟你的 職業 生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.