Вопрос

I am executing the following gnuplot script:

set terminal svg
set output "file.svg"
set yrange [0:1]
set style fill solid
set key top left
set style fill transparent solid 0.6 border lt -1
set palette model RGB defined (1 "red", 2 "blue")
set xtics rotate by -45
plot "file.data" using 3:xticlabels(2):1 title "" with boxes palette

and file.data looks like this:

1   name1   0.356877
1   name2   0.643123
2   name3   0.688312
2   name4   0.311688

So I want the boxes with leading 2's in the data file to be blue, and the ones with a 1 in front to be red.

It fails when I add the palette keyword and prints the error message in the title.

Gnuplot is v4.6 patchlevel 4, I am running it on Ubuntu 14.04. I have created coloured plots this way before, so this probably is just a tiny error I am overlooking, but I'm all out of ideas.

Это было полезно?

Решение

Your script has two errors:

incorrect format specifier

According to the gnuplot documentation (? boxes at the command line) if three columns of input are provided to plot with boxes, the third column is a width parameter for the boxes. Using a variable line/fill color requires adding an additional column of input:

plot "file.data" using 0:3:(1):1 with boxes

An explanation of the four columns:

  1. Column 0 provides an index: the first is 0, second is 1 etc. These give the x position (assuming each box is an individual).
  2. Column 3 is your y data.
  3. Column (1) provides the numerical value 1 for the x width of your boxes.
  4. Column 1 provides your color information.

missing lc (linecolor) parameter to plot command

Your whole plot command should look like plot "file.data" using 0:3:(1):1 title "" with boxes lc palette

also note

Keep in mind that the palette information is rescaled to be between the min/max values of cbrange. What I mean is that if your data is binary (1 or 2 in this case) the palette will be constructed properly, but if you want more specific colors (e.g. for data values 1/2/3) and you set a three-color palette in the same way it may not work the way you expect.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top