从 matplotlib 中给定的颜色图创建颜色生成器
我有一系列线条,每条线条都需要用单独的颜色绘制。每条线实际上由多个数据集(正区域、负区域等)组成,因此我希望能够创建一个生成器,在整个光谱中一次提供一种颜色,例如 gist_rainbow 地图此处显示。
我找到了以下作品,但看起来很复杂,更重要的是很难记住,
from pylab import *
NUM_COLORS = 22
mp = cm.datad['gist_rainbow']
get_color = matplotlib.colors.LinearSegmentedColormap.from_list(mp, colors=['r', 'b'], N=NUM_COLORS)
...
# Then in a for loop
this_color = get_color(float(i)/NUM_COLORS)
而且它没有涵盖 gist_rainbow
地图中的颜色范围,我必须重新定义地图。
也许生成器不是最好的方法,如果是的话,可接受的方法是什么?
I have a series of lines that each need to be plotted with a separate colour. Each line is actually made up of several data sets (positive, negative regions etc.) and so I'd like to be able to create a generator that will feed one colour at a time across a spectrum, for example the gist_rainbow
map shown here.
I have found the following works but it seems very complicated and more importantly difficult to remember,
from pylab import *
NUM_COLORS = 22
mp = cm.datad['gist_rainbow']
get_color = matplotlib.colors.LinearSegmentedColormap.from_list(mp, colors=['r', 'b'], N=NUM_COLORS)
...
# Then in a for loop
this_color = get_color(float(i)/NUM_COLORS)
Moreover, it does not cover the range of colours in the gist_rainbow
map, I have to redefine a map.
Maybe a generator is not the best way to do this, if so what is the accepted way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要从特定颜色图中索引颜色,您可以使用:
To index colors from a specific colormap you can use: