如何基於 Matplotlib 中的配色圖在散點圖中為點著色?
要基於配色圖在散點圖中為點著色,我們可以在 scatter() 方法中使用 copper 配色圖。
步驟
設定圖形大小並調整子圖之間及周圍的邊距。
使用 numpy 建立 x 和 y 100 個隨機資料點。
用 color=x 和 colormap=copper 繪製散點 x 和 y。
要顯示圖形,請使用 show() 方法。
示例
import numpy as np from matplotlib import pyplot as plt, cm plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.random.rand(100) y = np.random.rand(100) plt.scatter(x, y, c=x, cmap='copper') plt.show()
輸出
廣告