1

I have data I want to display using plt.imshow(), using red shades for positive values and green shades for negative values, with a sharp transition from green to red at zero, so it is easy to see whether values are positive or negative. The closest I have found in matplotlib's built-in colormaps is 'PiYG', but this displays purple rather than red, and I'd prefer a sharper transition at the point where the colours change, without the yellowish shades. Do you know of a way to get a good colormap with the properties that I want?

PeterW
  • 311
  • 2
  • 5
  • 13
  • Despite it being possible to do this (see the linked duplicated), you might consider that using red and green on the same colormap is not a great idea, since people with red-green colourblindness will not be able to interpret your plot. – tmdavison Dec 18 '17 at 16:07
  • That is a fair point – PeterW Dec 18 '17 at 23:00

1 Answers1

-1

I had a go at defining my own colormap using the code below, which seems to give a reasonable result, but could still be improved upon I think:

    cdict = {'red':  ((0.0, 0.0, 0.0),
                 (1/6., 0.0, 0.0),
                 (1/2., 0.8, 1.0),
                 (5/6., 1.0, 1.0),
                 (1.0, 0.4, 1.0)),

             'green':  ((0.0, 0.0, 0.4),
                 (1/6., 1.0, 1.0),
                 (1/2., 1.0, 0.8),
                 (5/6., 0.0, 0.0),
                 (1.0, 0.0, 0.0)),

             'blue': ((0.0, 0.0, 0.0),
                 (1/6., 0.0, 0.0),
                 (1/2., 0.9, 0.9),
                 (5/6., 0.0, 0.0),
                 (1.0, 0.0, 0.0))

        }

    cmap=LinearSegmentedColormap('rg',cdict, N=256)
PeterW
  • 311
  • 2
  • 5
  • 13
  • Note switching the green and blue numbers gives a decent-looking red-blue colormap as well. – PeterW Dec 18 '17 at 15:38
  • As it stands, the question is not clear enough to be answered by anyone besides yourself. Can you clean it up a bit? Some code / [mcve] would help too. – cs95 Dec 18 '17 at 15:40