以十六進位制格式提取 Matplotlib 顏色對映


若要提取十六進位制格式的 Matplotlib 顏色對映,我們可以按以下步驟進行 −

  • 獲取彩虹顏色對映。

  • 在彩虹顏色對映長度的範圍內進行迭代。

  • 使用 rgb2hex 方法,將rgba 元組轉換為顏色的十六進位制表示形式。

示例

from matplotlib import cm
import matplotlib

cmap = cm.rainbow
for i in range(cmap.N):
   rgba = cmap(i)
   print("Hexadecimal representation of rgba:{} is {}".format(rgba, matplotlib.colors.rgb2hex(rgba)))

輸出

...............
........................
....................................
Hexadecimal representation of rgba:(1.0, 0.3954512068705424, 0.2018824091570102,
1.0) is #ff6533
Hexadecimal representation of rgba:(1.0, 0.38410574917192575, 0.1958454670071669,
1.0) is #ff6232
Hexadecimal representation of rgba:(1.0, 0.37270199199091436,
0.18980109344182594, 1.0) is #ff5f30
.........................................................

更新日期:06-May-2021

1 千+ 瀏覽

開啟您的 職業生涯

完成課程,獲得認證

開始學習
廣告
© . All rights reserved.