官網:Choosing Colormaps in Matplotlib — Matplotlib 3.5.0 documentation
Colormap與matplotlib.cm
我們以等高區域函數contourf為例,介紹matplotlib.cm的用法。關於contourf各參數的具體用法,這里不多說,有需要可以參考Python:matplotlib.pyplot - ShineLe - 博客園
plt.contourf( X , Y , Z,...,cmap=? )
在用contourf繪制等值區域時,cmap參數指定了色表樣式,它有兩種寫法——str或Colormap實例,舉例來說:
plt.contourf( X , Y , Z,...,cmap='hot' ) #等價於 plt.contourf( X , Y , Z,...,cmap=matplotlib.cm.hot)
以上都是用同一個colormap進行等值區域繪制的,結果如下:
這就是colormap的用法。而matplotlib.cm中提供許多colormap,足夠我們日常工作學習需要。
matplotlib.cm中的色表
官網:Colormap reference — Matplotlib 3.5.0 documentation
使用時,在需要填入colormap的地方,可以通過兩種寫法使用colormap,①字符串形式的色表名:'hot';②matplotlib.cm.色表名:matplotlib.cm.hot。
cm中的色表羅列如下:
binary為灰度圖像標准色表