1
votes

I'm using this minimal sample:

set xrange [0:10]
plot x**2

This produces a nice smooth graph. However, I'd like that there are only points plotted on natural values for x (0, 1, 2, ..., 10), making the chart 'rigid', something like this:

enter image description here

Is there a possibility to do this without a data file?

I know about Gnuplot x-axis resolution, however, if I would use that, I would need to tweak the sample resolution every time I change the xrange.

2

2 Answers

1
votes

using shell

Instead of a file, you can pipe a shell command to give you the points you want :

plot "<seq 0 10" using 1:($1**2) w lp

portability ?

See this documentation : http://www.chemie.fu-berlin.de/chemnet/use/info/gnuplot/gnuplot_13.html#SEC53, I quote :

On some computer systems with a popen function (UNIX), the datafile can be piped through a shell command by starting the file name with a '<'.

Apparently this also works on some windows systems (with cygwin), though other windows platform fail with a miserable error (see below). This seems to be in that case because gnuplot opens a windows batch shell.

If however you try to call a shell command through the system("command") way, you get a more explicit error (at least on my windows) :

gnuplot> plot "<echo 0 1 2 3 4 5 6 7 8 9 10" using 1:($1**2) w lp  \
         # fails, implying the < syntax doesn't even exist
     warning: Skipping unreadable file "<echo 0 1 2 3 4 5 6 7 8 9 10"
     No data in plot

gnuplot> plot system("echo 0 1 2 3 4 5 6 7 8 9 10") using 1:($1**2) w lp \
         # fails with proper warning, then tries to reuse previous file
     warning: system() requires support for pipes
     warning: Skipping unreadable file "<echo 0 1 2 3 4 5 6 7 8 9 10" 
     No data in plot

gnuplot> !pause # shows a windows batch window
1
votes

If you want points, you can use the pseudo-file "+". It is like a file containing a series of numbers in a single column. You have to set the xrange. The number of points is determined by set samples :

set xrange[-5:5]
set samples 11 # need 11 points: 0, 1, 2, ..., 10
plot "+" u 1:($1**2) with linespoints

EDIT:

First, it is true: you do not have to use '+' just for linespoints...

OK, what's about this:

plot '+' u (floor($1)):(floor($1)**2) smooth unique w lp

Still using the pseudo-file '+', it rounds down its values to the next integer. As log ans you ensure that the number of sample points is high enough that there's alway one number generated beween each integer (let's say twice the full yrange), it works. The smooth unique prevents multible points at the same coordinates. enter image description here