From: Timothy W. H. <hi...@me...> - 2010-12-09 03:15:54
|
Hello, I'm trying to teach myself to create custom colormaps to highlight certain aspects of a dataset I am working with. The script below produces two plots -- the first shows a 4x4 array foo of random floats between 0.0 and 1.0, and the second shows the same array, but normalized such that [foo.min(), foo.max()] is mapped to [0.0, 1.0]. As I understand it, I am plotting two slightly different datasets using the same colormap, yet the two colorbars are different -- note the value at the transition from grayscale to red. I am not sure whether the colors are being assigned to slightly different data values in the two plots, or if the problem is in plotting the colorbar. I'd appreciate any help! Thanks, Tim -- Timothy W. Hilton PhD Candidate, Department of Meteorology The Pennsylvania State University 503 Walker Building, University Park, PA 16802 hi...@me... ========= import numpy as np import numpy.ma as ma import matplotlib.pyplot as plt import matplotlib as mpl mycmdata1 = {'red': ((0.0, 0.0, 0.0), (0.5, 1.0, 0.7), (1.0, 1.0, 1.0)), 'green': ((0.0, 0.0, 0.0), (0.5, 1.0, 0.0), (1.0, 1.0, 1.0)), 'blue': ((0.0, 0.0, 0.0), (0.5, 1.0, 0.0), (1.0, 0.5, 1.0))} mycm1 = mpl.colors.LinearSegmentedColormap('mycm1', mycmdata1) N = 4 np.random.seed(0) foo = np.random.rand(N, N) plt.figure() plt.pcolor(foo, cmap=mycm1) plt.colorbar() plt.figure() norm = mpl.colors.Normalize() plt.pcolor(norm(foo), cmap=mycm1) plt.colorbar() |