本文簡要介紹 python 語言中 matplotlib.colors.LinearSegmentedColormap
的用法。
-
基礎:
Colormap
基於使用線性段的查找表的顏色圖對象。
查找表是針對每種原色使用線性插值生成的,其中 0-1 域分為任意數量的段。
從線性映射段創建顏色圖
segmentdata 參數是一個帶有紅色、綠色和藍色條目的字典。每個條目應該是
x
、y0
、y1
元組的列表,在表中形成行。 alpha 條目是可選的。示例:假設您希望紅色在下半部分從 0 增加到 1,綠色在中半部分執行相同的操作,藍色在上半部分執行。然後你會使用:
cdict = {'red': [(0.0, 0.0, 0.0), (0.5, 1.0, 1.0), (1.0, 1.0, 1.0)], 'green': [(0.0, 0.0, 0.0), (0.25, 0.0, 0.0), (0.75, 1.0, 1.0), (1.0, 1.0, 1.0)], 'blue': [(0.0, 0.0, 0.0), (0.5, 0.0, 0.0), (1.0, 1.0, 1.0)]}
表中給定顏色的每一行都是
x
、y0
、y1
元組的序列。在每個序列中,x
必須從 0 到 1 單調遞增。對於介於x[i]
和x[i+1]
之間的任何輸入值z
;給定顏色的輸出值將在y1[i]
和y0[i+1]
之間線性插值:row i: x y0 y1 / / row i+1: x y0 y1
因此,從不使用第一行中的 y0 和最後一行中的 y1。
用法
class matplotlib.colors.LinearSegmentedColormap(name, segmentdata, N=256, gamma=1.0)
相關用法
- Python matplotlib LineCollection.set_hatch用法及代碼示例
- Python matplotlib LineCollection.sticky_edges用法及代碼示例
- Python matplotlib LassoSelector用法及代碼示例
- Python matplotlib axvspan用法及代碼示例
- Python matplotlib Axes.get_legend_handles_labels用法及代碼示例
- Python matplotlib AbstractMovieWriter用法及代碼示例
- Python matplotlib triplot用法及代碼示例
- Python matplotlib StarPolygonCollection.set_hatch用法及代碼示例
- Python matplotlib Axes.hist用法及代碼示例
- Python matplotlib boxplot用法及代碼示例
- Python matplotlib subplots用法及代碼示例
- Python matplotlib InsetPosition用法及代碼示例
- Python matplotlib ToolManager.toolmanager_disconnect用法及代碼示例
- Python matplotlib Figure.set_size_inches用法及代碼示例
- Python matplotlib figlegend用法及代碼示例
- Python matplotlib Axes.step用法及代碼示例
- Python matplotlib Axes.contour用法及代碼示例
- Python matplotlib BrokenBarHCollection.set_hatch用法及代碼示例
- Python matplotlib Axes.plot用法及代碼示例
- Python matplotlib Axes.semilogx用法及代碼示例
- Python matplotlib Axes.semilogy用法及代碼示例
- Python matplotlib MovieWriterRegistry.register用法及代碼示例
- Python matplotlib PolyQuadMesh.set_hatch用法及代碼示例
- Python matplotlib warn_deprecated用法及代碼示例
- Python matplotlib Text.set_bbox用法及代碼示例
注:本文由純淨天空篩選整理自skytowner.com大神的英文原創作品 matplotlib.colors.LinearSegmentedColormap。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。