2
votes

I have a problem with setting the x and ytics in gnuplot. I want to create heat maps, and to do it I need specific tics for each "block" in them. I want to create them with loops, so it is much easier to work with them, because for instance I need to make like 60 xtics so I have to write down this:

set xtics ("-0.3" 0, "-0.29" 1, ... "0.3" 60)

It is exhausting and frustrating, so I wanted to make a script like this:

xnumtics = 60
ynumtics = 90
set macros

xticstring = '('

do for [i=0:xnumtics] {
    xticstring = xticstring.'"'.(-0.3 + i*0.01).'" '.i.', '
}

xticstring = xticstring.'"'.0.3.'" '.xnumtics.')'

set xtics @xticstring

yticstring = '('

do for [j=0:ynumtics] {
    yticstring = yticstring.'"'.(0 - i*0.01).'" '.j.', '
}

yticstring = yticstring.'"'.0.9.'"'.ynumtics.' '

set ytics @yticstring

Unfortunately I get an error: line 21: internal error : STRING operator applied to non-STRING type

line 21 refers for: xticstring = xticstring.'"'.(-0.3 + i*0.01).'" '.i.','

I got this idea from: Can GNUPLOT dynamically prepare index labels?

I am using gnuplot 4.6 ptchlvl 4 on ubuntu 14.04 LTS

Sorry if it is too trivial, I cannot figure it out what is the problem...

Thank you!

1

1 Answers

3
votes

The string concatenation operator . can automatically convert only integer numbers, not doubles. You would need to use sprintf or gprintf to convert the (-0.3 + i*0.01) to a string.

However, a shorter way to set the tics would be to use set for ... iterations:

xnumtics = 60
ynumtics = 90

set xtics () # clear all tics
set for [i=0:xnumtics] xtics add (gprintf("%g", -0.3 + i * 0.01) i)

set ytics ()
set for [i=0:ynumtics] ytics add (gprintf("%g",  -i * 0.01) i)

Do you really need to manually add the tics? Usually one maps the values from a data file to use gnuplot's usual numerical axes:

plot 'file.dat' using (-0.3 + $1 * 0.01):($2 * -0.01)