2

For a density plot I need a colormap ranging from maroon over red, yellow, green, blue to black. I defined the following colormap:

    cdict1 = {'maroon':   ((0.0, 0.0, 0.8),
                       (1/6, 1.0, 1.0)),

             'red': ((1/6, 0.0, 0.8),
                       (2/6, 1.0, 0.0)),

             'yellow':  ((2/6, 0.0, 0.8),
                       (3/6, 1.0, 0.0)),

            'green':   ((3/6, 0.0, 0.8),
                       (4/6, 1.0, 0.0)),

             'blue': ((4/6, 0.0, 0.8),
                       (5/6, 1.0, 0.0)),

             'black':  ((5/6, 0.0, 0.8),
                       (1.0, 1.0, 0.0))
            }

wblack = LinearSegmentedColormap('wblack', cdict1)
plt.register_cmap(cmap=wblack)

Colormap legend:

But the "black" is completely ignored such that the colormap ranges from maroon to dark blue but not to black. Can somebody tell me what I´m doing wrong and how to correctly add black to my colormap?

Mirza Sisic
  • 2,401
  • 4
  • 24
  • 38
berti
  • 53
  • 7
  • 1
    Which version of python? `5/6` could be zero. – Peter Wood Mar 15 '16 at 10:33
  • 1
    That is not how `LinearSegmentedColormap`s work. Only the 'red', 'green' and 'blue' entries in the dictionary are used. http://matplotlib.org/api/colors_api.html?highlight=linearsegmentedcolormap#matplotlib.colors.LinearSegmentedColormap – tacaswell Mar 15 '16 at 12:46
  • 2
    Also, you're not actually *using* the colormap that you're creating. The one that you are showing is actually just the default `jet` colormap. You have to actually specify the colormap when plotting something rather than simply registering it. – Suever Mar 15 '16 at 12:48
  • That's it, Suever. I solved the problem. Thanks! – berti Mar 22 '16 at 08:40

0 Answers0