Kyle Ghaby
Kyle Ghaby

Reputation: 13

Gnuplot - How do I plot one column of data at assigned xtics?

I have one column of data (y axis) where each of 4 rows corresponds to a temperature (x axis). I can use xtics from 0-3 for the four temperatures, but the xtic labels represent temperatures with uneven intervals. I want to plot each row of data at specified xtics so the intervals reflect that of the temperatures. Is this possible?

Using the following instructions

set xrange [0:3]
set xtics ("253" 0, "294" 1, "310" 2, "350" 3)

I get my four rows plotted at the four temperatures, but the x values are evenly spaced by 1 tic. I'd rather have my data spaced to the same xtic values as the temperature.

I thought I could use

set xtics ("253" 253, "294" 294, "310" 310, "350" 350)

but the data is still plotted at tics 0-3.

Can I use something like

plot "file.dat" using 1:xtics(253,294,310,350)

This doesn't work but it's just an idea. Thank you in advance for any input and help!

Upvotes: 0

Views: 1192

Answers (2)

theozh
theozh

Reputation: 26198

Another ("ugly") workaround: if you have only 4 rows you can do the following. Works also with gnuplot 4.0.

myTic(n) = n==0 ? 253 : n==1 ? 294 : n==2 ? 310 : n==3 ? 350 : NaN

plot 'file.dat' u (myTic($0)):1

Upvotes: 0

Ethan
Ethan

Reputation: 15118

The usual thing would be to place the temperatures in a separate column and use that column for the x coordinate. But if you really want to insert the temperature values only inside the plotting script I suggest:

array temperature[4] = [253,294,310,350]
plot "file.dat" using (temperature[$0+1]):1 

Note that the row numbers run from 0-3 but the array indices run from 1-4.

If your gnuplot is too old to support arrays you might still be able to use a multi-word string instead. Warning: this syntax is really ugly!

temperature = "253 294 310 350"
plot "file.dat" using (word(temperature,int(column(0))+1)+0.0):1

Upvotes: 1

Related Questions