Reds and Greens colormap starting with black

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Reds and Greens colormap starting with black

Kesavan Subburam
Hi matplotlib users,

I was wondering if anyone knows a way to modify the Reds and Greens colormap such that the lower end of the colormaps is not a mixture of white and red or green, but black and red or green respectively.

I tried to do this by making the image RGB, with my data only in the red or green channel, but matplotlib only supports int8 but my images have higher dynamic range, and they lose resolution if I cast them from int16 to int8. Here's the code:

def color(img):
    x, y = img.shape
    c = np.zeros((x, y, 3), dtype=np.uint8)
    c[:, :, 0] = img
    return c

Thank you and best regards,
Kesavan

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Reds and Greens colormap starting with black

Eric Firing
Kesavan,

Check out the BlueRed1 colormap near the bottom of
https://matplotlib.org/gallery/images_contours_and_fields/custom_cmap.html?highlight=linearsegmentedcolormap.
  It is shown in the upper-left panel of the figure at the very bottom.
It is not exactly what you are asking for, but it illustrates how to
make simple colormaps that shade into black.

Alternatively, for a good colormap tool, see
https://github.com/matplotlib/viscm.  You should be able to get a much
better result with this than with simple linear ramps in RGB space.

Eric

On 2017/12/19 9:12 PM, Kesavan Subburam wrote:

> Hi matplotlib users,
>
> I was wondering if anyone knows a way to modify the Reds and Greens
> colormap such that the lower end of the colormaps is not a mixture of
> white and red or green, but black and red or green respectively.
>
> I tried to do this by making the image RGB, with my data only in the red
> or green channel, but matplotlib only supports int8 but my images have
> higher dynamic range, and they lose resolution if I cast them from int16
> to int8. Here's the code:
>
> def color(img):
>      x, y = img.shape
>      c = np.zeros((x, y, 3), dtype=np.uint8)
>      c[:, :, 0] = img
>      return c
>
> Thank you and best regards,
> Kesavan
>
>
> _______________________________________________
> Matplotlib-users mailing list
> [hidden email]
> https://mail.python.org/mailman/listinfo/matplotlib-users
>

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users