Skip to content Skip to sidebar Skip to footer

Pyplot Colormesh Creates Plot With Wrong Color Mapping

I try to create a Color Mesh plot using a map of xy-coordinates and colors in this way: from matplotlib.colors import ListedColormap import numpy as np %pylab inline colors = List

Solution 1:

Colormaps are normalized between 0 and 1. When they are used in a plot, the normalization is transfered to the minimum and maximum value of the data. If 0 and 1 are minimum and maximum, 0 will be the first color of the map (red) and 1 will the last (yellow).

What you need is a normalization which takes the desired colormap behaviour into account. The easiest option is to use vmin and vmax

zz = np.array([[1,1,1,1,1],
               [1,1,1,1,1],
               [1,1,1,1,1],
               [0,0,0,0,0],
               [0,0,0,0,0]])
plt.pcolormesh(xx, yy, zz, cmap = colors, vmin=0,vmax=colors.N)

enter image description here

Post a Comment for "Pyplot Colormesh Creates Plot With Wrong Color Mapping"