【问题标题】:Get Access to colormap "jet"访问颜色图“jet”
【发布时间】:2020-12-13 22:38:18
【问题描述】:

我需要访问预定义的颜色映射“jet”。 我找到了一个访问地图“vidiris”的示例

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.colors import ListedColormap, LinearSegmentedColormap
viridis = cm.get_cmap('viridis', 12)
print('viridis.colors', viridis.colors)

这给了我地图的前 12 行,但我无法访问地图“jet”

【问题讨论】:

  • 使用cm.get_cmap('jet')会发生什么?

标签: python matplotlib colors


【解决方案1】:

jet 颜色图是一个 LinearSegmentedColormap,它没有 .colors 属性。以下方法从jet 颜色图中获取 12 种等距颜色:

from matplotlib import pyplot as plt
from matplotlib import cm
import numpy as np

jet = cm.get_cmap('jet')
jet_12_colors = jet(np.linspace(0, 1, 12))
print('jet.colors', jet_12_colors)

viridis = cm.get_cmap('viridis', 12)
print('viridis.colors', viridis.colors)

plt.scatter(range(12), np.repeat(2, 12), color=jet_12_colors)
plt.scatter(range(12), np.repeat(1, 12), color=viridis.colors)
plt.xticks(range(12))
plt.show()

【讨论】:

  • 这能回答你的问题吗?或者您在哪里寻找其他东西?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-03-23
  • 2020-10-23
  • 2011-03-16
  • 2011-10-26
  • 2021-09-06
  • 2013-01-02
  • 1970-01-01
相关资源
最近更新 更多