Gnuplot rgb color schemes in matlab as colormaps

I like the color schemes that are used as palettes in gnuplot’s pm3d plots. I wanted similar color schemes that can be used as colormaps in matlab.

After reading this article, I found that  one can easily incorporate the traditional rgbpallette schemes in matlab

To start, there are several schemes in gnuplot  that can be used in pm3d plots and they are:

7,5,15   ... traditional pm3d (black-blue-red-yellow)
3,11,6   ... green-red-violet
23,28,3  ... ocean (green-blue-white); try also all other permutations
21,22,23 ... hot (black-red-yellow-white)
30,31,32 ... color printable on gray (black-blue-violet-yellow-white)
33,13,10 ... rainbow (blue-green-yellow-red)
34,35,36 ... AFM hot (black-red-yellow-white)

The numbers represent different mapping functions for red, green and blue and the functions are

0: 0               1: 0.5             2: 1
3: x               4: x^2             5: x^3
6: x^4             7: sqrt(x)         8: sqrt(sqrt(x))
9: sin(90x)       10: cos(90x)       11: |x-0.5|
12: (2x-1)^2       13: sin(180x)      14: |cos(180x)|
15: sin(360x)      16: cos(360x)      17: |sin(360x)|
18: |cos(360x)|    19: |sin(720x)|    20: |cos(720x)|
21: 3x             22: 3x-1           23: 3x-2
24: |3x-1|         25: |3x-2|         26: (3x-1)/2
27: (3x-2)/2       28: |(3x-1)/2|     29: |(3x-2)/2|
30: x/0.32-0.78125 31: 2*x-0.84       32: 4x;1;-2x+1.84;x/0.08-11.5
33: |2*x - 0.5|    34: 2*x            35: 2*x - 0.5
36: 2*x - 1
* negative numbers mean inverted=negative colour component
* thus the ranges in `set pm3d rgbformulae' are -36..36

For example, if we choose, 7,5,15 , ie, traditional pm3d (black-blue-red-yellow), the three numbers correspond to functions used for red, green and blue respectively. So in this case, red(x)=sqrt(x), green(x)=x^3 and blue(x)=sin(2*pi*x), where x has range from 0 to 1. Note that red(x)/green(x)/blue(x) should not be negative numbers, so if they are negative make then zeros.

With that knowledge, here is a matlab code that creates 7,5,15 and 3,11,6 colormaps and uses it in the display of an image.

clear all
x=linspace(0,1,128);
r = sqrt(x);
g = x.^3.0;
b=sin(x*2*pi);
b(b<0)=0;
pm3d7515_bbry=[r;g;b]'
figure
load mandrill;
imagesc(X);
colormap(pm3d7515_bbry);
colorbar

r = x;
g = abs(x-0.5);
b=x.^4;
pm3d3116_grv=[r;g;b]'
figure
load mandrill;
imagesc(X);
colormap(pm3d3116_grv);
colorbar

This results are shown below. Other color schemes can be similarly incorporated into matlab codes.

2 thoughts on “Gnuplot rgb color schemes in matlab as colormaps

  1. Great!, i was looking for something like this, i needed the color schemes, i’m using pyxplot and it was so difficult to find a site that explains the functions used by color schemes.

    Manyt thanks :)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>