Create scientific plots using gnuplot

June 10th, 2012 | 6 Comments

In one off the last entries we defined a color palette similar to the default one in Matlab. Now we will use a color palette with only a few discrete colors, as shown in Fig. 1. This can be useful if we want to see all values from a measurement lying above a given threshold.

Palette with discrete colors

Fig. 1 Photoluminescence yield plotted with a palette with discrete colors (code to produce this figure, data)

The trick is to set maxcolors to the number of colors you want in your plot. In addition, the colors to use can be specified by the defined command. Note, that the absolute values you specify in the palette definition were automatically scaled to your min and max values (0 and 18 in this case).

set palette maxcolors 3
set palette defined ( 0 '#000fff',\
                      1 '#90ff70',\
                      2 '#ee0000')


  1. Arturo says:

    How can I plot the colorbox marks labels (2, 4, ….) *inside* the colorbox?
    Thanks again for your website!!!

  2. Arturo says:

    I’ve found it:

    set cbtics font “Helvetica,8” #smaller font
    set format cb “%2.0f” #format
    set cbtics offset -2 #change location

  3. hemmer says:

    A much simpler way to do this is to use:

    set palette maxcolors N

    where N is the number of levels to use.

  4. hagen says:

    Thanks, that is a much nicer method.
    I have updated the post to include maxcolors.

  5. kipgon says:


    first I would like to thank you for your very interesting and helpful website.

    I also would like to ask you a question because after a lot of test, I didn’t manage to use maxcolors with a defined palette.

    Do you know how to fix this issue ?

    Thanks in advance

  6. hagen says:

    Hi kipgon,

    what exactly happens if you try to replot Fig. 1?

Leave a Reply