|
1 | 1 | """
|
2 |
| -Color data and pre-defined cmap objects. |
| 2 | +Nothing here but dictionaries for generating LinearSegmentedColormaps, |
| 3 | +and a dictionary of these dictionaries. |
3 | 4 |
|
4 |
| -This is a helper for cm.py, originally part of that file. |
5 |
| -Separating the data (this file) from cm.py makes both easier |
6 |
| -to deal with. |
7 |
| -
|
8 |
| -Objects visible in cm.py are the individual cmap objects ('autumn', |
9 |
| -etc.) and a dictionary, 'datad', including all of these objects. |
10 | 5 | """
|
11 | 6 |
|
12 |
| -import matplotlib as mpl |
13 |
| -import matplotlib.colors as colors |
14 |
| -LUTSIZE = mpl.rcParams['image.lut'] |
15 |
| - |
16 | 7 | _binary_data = {
|
17 | 8 | 'red' : ((0., 1., 1.), (1., 0., 0.)),
|
18 | 9 | 'green': ((0., 1., 1.), (1., 0., 0.)),
|
19 | 10 | 'blue' : ((0., 1., 1.), (1., 0., 0.))
|
20 | 11 | }
|
21 | 12 |
|
22 |
| - |
23 | 13 | _bone_data = {'red': ((0., 0., 0.),(1.0, 1.0, 1.0)),
|
24 | 14 | 'green': ((0., 0., 0.),(1.0, 1.0, 1.0)),
|
25 | 15 | 'blue': ((0., 0., 0.),(1.0, 1.0, 1.0))}
|
|
379 | 369 | (1.0, 0.80, 0.80)]}
|
380 | 370 |
|
381 | 371 |
|
382 |
| -autumn = colors.LinearSegmentedColormap('autumn', _autumn_data, LUTSIZE) |
383 |
| -bone = colors.LinearSegmentedColormap('bone ', _bone_data, LUTSIZE) |
384 |
| -binary = colors.LinearSegmentedColormap('binary ', _binary_data, LUTSIZE) |
385 |
| -cool = colors.LinearSegmentedColormap('cool', _cool_data, LUTSIZE) |
386 |
| -copper = colors.LinearSegmentedColormap('copper', _copper_data, LUTSIZE) |
387 |
| -flag = colors.LinearSegmentedColormap('flag', _flag_data, LUTSIZE) |
388 |
| -gray = colors.LinearSegmentedColormap('gray', _gray_data, LUTSIZE) |
389 |
| -hot = colors.LinearSegmentedColormap('hot', _hot_data, LUTSIZE) |
390 |
| -hsv = colors.LinearSegmentedColormap('hsv', _hsv_data, LUTSIZE) |
391 |
| -jet = colors.LinearSegmentedColormap('jet', _jet_data, LUTSIZE) |
392 |
| -pink = colors.LinearSegmentedColormap('pink', _pink_data, LUTSIZE) |
393 |
| -prism = colors.LinearSegmentedColormap('prism', _prism_data, LUTSIZE) |
394 |
| -spring = colors.LinearSegmentedColormap('spring', _spring_data, LUTSIZE) |
395 |
| -summer = colors.LinearSegmentedColormap('summer', _summer_data, LUTSIZE) |
396 |
| -winter = colors.LinearSegmentedColormap('winter', _winter_data, LUTSIZE) |
397 |
| -spectral = colors.LinearSegmentedColormap('spectral', _spectral_data, LUTSIZE) |
398 |
| - |
399 |
| - |
400 |
| - |
401 |
| -datad = { |
402 |
| - 'autumn': _autumn_data, |
403 |
| - 'bone': _bone_data, |
404 |
| - 'binary': _binary_data, |
405 |
| - 'cool': _cool_data, |
406 |
| - 'copper': _copper_data, |
407 |
| - 'flag': _flag_data, |
408 |
| - 'gray' : _gray_data, |
409 |
| - 'hot': _hot_data, |
410 |
| - 'hsv': _hsv_data, |
411 |
| - 'jet' : _jet_data, |
412 |
| - 'pink': _pink_data, |
413 |
| - 'prism': _prism_data, |
414 |
| - 'spring': _spring_data, |
415 |
| - 'summer': _summer_data, |
416 |
| - 'winter': _winter_data, |
417 |
| - 'spectral': _spectral_data |
418 |
| - } |
419 |
| - |
420 | 372 | # 34 colormaps based on color specifications and designs
|
421 | 373 | # developed by Cynthia Brewer (http://colorbrewer.org).
|
422 | 374 | # The ColorBrewer palettes have been included under the terms
|
|
5859 | 5811 | 0.0078431377187371254, 0.0078431377187371254), (1.0,
|
5860 | 5812 | 0.0039215688593685627, 0.0039215688593685627)]}
|
5861 | 5813 |
|
5862 |
| -Accent = colors.LinearSegmentedColormap('Accent', _Accent_data, LUTSIZE) |
5863 |
| -Blues = colors.LinearSegmentedColormap('Blues', _Blues_data, LUTSIZE) |
5864 |
| -BrBG = colors.LinearSegmentedColormap('BrBG', _BrBG_data, LUTSIZE) |
5865 |
| -BuGn = colors.LinearSegmentedColormap('BuGn', _BuGn_data, LUTSIZE) |
5866 |
| -BuPu = colors.LinearSegmentedColormap('BuPu', _BuPu_data, LUTSIZE) |
5867 |
| -Dark2 = colors.LinearSegmentedColormap('Dark2', _Dark2_data, LUTSIZE) |
5868 |
| -GnBu = colors.LinearSegmentedColormap('GnBu', _GnBu_data, LUTSIZE) |
5869 |
| -Greens = colors.LinearSegmentedColormap('Greens', _Greens_data, LUTSIZE) |
5870 |
| -Greys = colors.LinearSegmentedColormap('Greys', _Greys_data, LUTSIZE) |
5871 |
| -Oranges = colors.LinearSegmentedColormap('Oranges', _Oranges_data, LUTSIZE) |
5872 |
| -OrRd = colors.LinearSegmentedColormap('OrRd', _OrRd_data, LUTSIZE) |
5873 |
| -Paired = colors.LinearSegmentedColormap('Paired', _Paired_data, LUTSIZE) |
5874 |
| -Pastel1 = colors.LinearSegmentedColormap('Pastel1', _Pastel1_data, LUTSIZE) |
5875 |
| -Pastel2 = colors.LinearSegmentedColormap('Pastel2', _Pastel2_data, LUTSIZE) |
5876 |
| -PiYG = colors.LinearSegmentedColormap('PiYG', _PiYG_data, LUTSIZE) |
5877 |
| -PRGn = colors.LinearSegmentedColormap('PRGn', _PRGn_data, LUTSIZE) |
5878 |
| -PuBu = colors.LinearSegmentedColormap('PuBu', _PuBu_data, LUTSIZE) |
5879 |
| -PuBuGn = colors.LinearSegmentedColormap('PuBuGn', _PuBuGn_data, LUTSIZE) |
5880 |
| -PuOr = colors.LinearSegmentedColormap('PuOr', _PuOr_data, LUTSIZE) |
5881 |
| -PuRd = colors.LinearSegmentedColormap('PuRd', _PuRd_data, LUTSIZE) |
5882 |
| -Purples = colors.LinearSegmentedColormap('Purples', _Purples_data, LUTSIZE) |
5883 |
| -RdBu = colors.LinearSegmentedColormap('RdBu', _RdBu_data, LUTSIZE) |
5884 |
| -RdGy = colors.LinearSegmentedColormap('RdGy', _RdGy_data, LUTSIZE) |
5885 |
| -RdPu = colors.LinearSegmentedColormap('RdPu', _RdPu_data, LUTSIZE) |
5886 |
| -RdYlBu = colors.LinearSegmentedColormap('RdYlBu', _RdYlBu_data, LUTSIZE) |
5887 |
| -RdYlGn = colors.LinearSegmentedColormap('RdYlGn', _RdYlGn_data, LUTSIZE) |
5888 |
| -Reds = colors.LinearSegmentedColormap('Reds', _Reds_data, LUTSIZE) |
5889 |
| -Set1 = colors.LinearSegmentedColormap('Set1', _Set1_data, LUTSIZE) |
5890 |
| -Set2 = colors.LinearSegmentedColormap('Set2', _Set2_data, LUTSIZE) |
5891 |
| -Set3 = colors.LinearSegmentedColormap('Set3', _Set3_data, LUTSIZE) |
5892 |
| -Spectral = colors.LinearSegmentedColormap('Spectral', _Spectral_data, LUTSIZE) |
5893 |
| -YlGn = colors.LinearSegmentedColormap('YlGn', _YlGn_data, LUTSIZE) |
5894 |
| -YlGnBu = colors.LinearSegmentedColormap('YlGnBu', _YlGnBu_data, LUTSIZE) |
5895 |
| -YlOrBr = colors.LinearSegmentedColormap('YlOrBr', _YlOrBr_data, LUTSIZE) |
5896 |
| -YlOrRd = colors.LinearSegmentedColormap('YlOrRd', _YlOrRd_data, LUTSIZE) |
5897 |
| -gist_earth = colors.LinearSegmentedColormap('gist_earth', _gist_earth_data, LUTSIZE) |
5898 |
| -gist_gray = colors.LinearSegmentedColormap('gist_gray', _gist_gray_data, LUTSIZE) |
5899 |
| -gist_heat = colors.LinearSegmentedColormap('gist_heat', _gist_heat_data, LUTSIZE) |
5900 |
| -gist_ncar = colors.LinearSegmentedColormap('gist_ncar', _gist_ncar_data, LUTSIZE) |
5901 |
| -gist_rainbow = colors.LinearSegmentedColormap('gist_rainbow', _gist_rainbow_data, LUTSIZE) |
5902 |
| -gist_stern = colors.LinearSegmentedColormap('gist_stern', _gist_stern_data, LUTSIZE) |
5903 |
| -gist_yarg = colors.LinearSegmentedColormap('gist_yarg', _gist_yarg_data, LUTSIZE) |
| 5814 | +datad = { |
| 5815 | + 'autumn': _autumn_data, |
| 5816 | + 'bone': _bone_data, |
| 5817 | + 'binary': _binary_data, |
| 5818 | + 'cool': _cool_data, |
| 5819 | + 'copper': _copper_data, |
| 5820 | + 'flag': _flag_data, |
| 5821 | + 'gray' : _gray_data, |
| 5822 | + 'hot': _hot_data, |
| 5823 | + 'hsv': _hsv_data, |
| 5824 | + 'jet' : _jet_data, |
| 5825 | + 'pink': _pink_data, |
| 5826 | + 'prism': _prism_data, |
| 5827 | + 'spring': _spring_data, |
| 5828 | + 'summer': _summer_data, |
| 5829 | + 'winter': _winter_data, |
| 5830 | + 'spectral': _spectral_data |
| 5831 | + } |
| 5832 | + |
| 5833 | + |
5904 | 5834 | datad['Accent']=_Accent_data
|
5905 | 5835 | datad['Blues']=_Blues_data
|
5906 | 5836 | datad['BrBG']=_BrBG_data
|
|
5944 | 5874 | datad['gist_stern']=_gist_stern_data
|
5945 | 5875 | datad['gist_yarg']=_gist_yarg_data
|
5946 | 5876 |
|
5947 |
| -# reverse all the colormaps. |
5948 |
| -# reversed colormaps have '_r' appended to the name. |
5949 |
| - |
5950 |
| -def revcmap(data): |
5951 |
| - data_r = {} |
5952 |
| - for key, val in data.iteritems(): |
5953 |
| - valnew = [(1.-a, b, c) for a, b, c in reversed(val)] |
5954 |
| - data_r[key] = valnew |
5955 |
| - return data_r |
5956 |
| - |
5957 |
| -cmapnames = datad.keys() |
5958 |
| -for cmapname in cmapnames: |
5959 |
| - cmapname_r = cmapname+'_r' |
5960 |
| - cmapdat_r = revcmap(datad[cmapname]) |
5961 |
| - datad[cmapname_r] = cmapdat_r |
5962 |
| - locals()[cmapname_r] = colors.LinearSegmentedColormap(cmapname_r, cmapdat_r, LUTSIZE) |
| 5877 | + |
| 5878 | + |
| 5879 | + |
| 5880 | + |
0 commit comments