colormap draw a gradient map

This code files is to use the colormap draw gradient maps
start set:

cNorm = colors.Normalize(vmin=0, vmax=5)
scalarMap = cmx.ScalarMappable(norm=cNorm, cmap=jet)

It should be noted that setting vmin, vmax means that the minimum and maximum gradient subsequent pictures
added during the drawing

colorVal = scalarMap.to_rgba(i)

That correlation value may be mapped to the corresponding space rbg
process each note c in the drawing is only a number
, although gradual process, is actually a section drawn


import numpy as np
#%matplotlib inline
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d as p3d
import matplotlib.colors as colors
import matplotlib.cm as cmx

jet = cm = plt.get_cmap('Reds') 
#这里可以选择色条方案
#e.g. Greys, 'Blues'
cNorm = colors.Normalize(vmin=0, vmax=5)
scalarMap = cmx.ScalarMappable(norm=cNorm, cmap=jet)
print(scalarMap.get_clim()) 

fig = plt.figure()
ax = fig.add_subplot(111)

#------绘图---------------------
x = np.arange(10, 15, 1)
y = np.arange(10, 15, 1)

for i in range(5):
    colorVal = scalarMap.to_rgba(i)
    print(i, colorVal)
    ax.plot(x, y + i, c = colorVal )  
plt.show() 

Here Insert Picture Description

Published 36 original articles · won praise 0 · views 20000 +

Guess you like

Origin blog.csdn.net/weixin_38102912/article/details/101293798