Search code examples
gnuplot

how to fix the problem of the missing color pieces in the colorbox in gnuplot


I met a problem that when I draw a map using gnuplot, there would be a colorbox near the map which looks very weird. I blew up the colorbox and found that there were pieces with missing color, the picture is below. How can I fill the color for the colorbox? colorboxpicture

Here are the terminal type and the palette I used in in gnuplot.

set terminal postscript portrait color enhanced 12
set palette defined (-6.0 "#1B66B1",\
                     -4.8 "#1B66B1",\
                     -4.8 "#2A85DF",\
                     -3.6 "#2A85DF",\
                     -3.6 "#5FA3E7",\
                     -2.4 "#5FA3E7",\
                     -2.4 "#95C2EF",\
                     -1.2 "#95C2EF",\
                     -1.2 "#C9E0F7",\
                     -0.120000 "#C9E0F7",\
                     0.0 "#FFFFFF",\
                     0.0 "#FFFFFF",\
                     0.120000 "#F6D5CB",\
                     1.2 "#F6D5CB",\
                     1.2 "#EDAB96",\
                     2.4 "#EDAB96",\
                     2.4 "#E48062",\
                     3.6 "#E48062",\
                     3.6 "#DC562E",\
                     4.8 "#DC562E",\
                     4.8  "#AE3F1E",\
                     6.0  "#AE3F1E")

Solution

  • The ps file has no gaps. If you export it to a png, you may get some artifacts, but it is rather the issue of the ps file handler than the file itself. You can avoid this behavior by asking Gnuplot to produce a simpler eps that won't fail on your favorite eps editor, or you change how you process eps.

    change the palette to something more simple

    You can define the maximum number of different colors by the maxcolors option of the palette. This generates not more than maxcolors number of possible colors, but it is equidistant.

    set terminal postscript portrait color enhanced 12
    set o "discrete.eps"
    set palette defined (-6.0 "#1B66B1",\
                         -4.8 "#2A85DF",\
                         -3.6 "#5FA3E7",\
                         -2.4 "#95C2EF",\
                         -1.2 "#C9E0F7",\
                         0.0 "#FFFFFF",\
                         1.2 "#F6D5CB",\
                         2.4 "#EDAB96",\
                         3.6 "#E48062",\
                         4.8 "#DC562E",\
                         6.0 "#AE3F1E") maxcolors 11
    set samples 20
    set isosamples 20
    splot sin(sqrt(x**2+y**2))/sqrt(x**2+y**2) w pm3d
    

    When inspecting the color bar, you can notice the small gap rendered on the png (but not in the eps) after I created the png using Inkscape:

    enter image description here

    keep the original palette, but change the way you process eps

    If you keep the original palette, it generates hundreds of color possibilities, but most of them will collide according to the step-like function you introduced in the color palette.

    set terminal postscript portrait color enhanced 12
    set o "discrete.eps"
    set palette defined (-6.0 "#1B66B1",\
                         -4.8 "#1B66B1",\
                         -4.8 "#2A85DF",\
                         -3.6 "#2A85DF",\
                         -3.6 "#5FA3E7",\
                         -2.4 "#5FA3E7",\
                         -2.4 "#95C2EF",\
                         -1.2 "#95C2EF",\
                         -1.2 "#C9E0F7",\
                         -0.12 "#C9E0F7",\
                         -0.12 "#FFFFFF",\
                         0.12 "#FFFFFF",\
                         0.12 "#F6D5CB",\
                         1.2 "#F6D5CB",\
                         1.2 "#EDAB96",\
                         2.4 "#EDAB96",\
                         2.4 "#E48062",\
                         3.6 "#E48062",\
                         3.6 "#DC562E",\
                         4.8 "#DC562E",\
                         4.8 "#AE3F1E",\
                         6.0 "#AE3F1E")
    set samples 20
    set isosamples 20
    splot sin(sqrt(x**2+y**2))/sqrt(x**2+y**2) w pm3d
    set o
    set term wxt
    

    Open the eps using different editors to see how it looks like. Use gimp and you'll get something like the fig below. enter image description here

    If you use Inkscape first, which can handle eps natively, it can produce the artifacts.

    You can convert the eps to pdf using ghostscript's ps2pdf.