Spacing between tics in Gnuplot - gnuplot

I've been going crazy looking for an answer to this question. How can I set the distance between the tics on gnuplot? Currently the tics in my plot are squished together too tightly. I want them to be more spread out.
Here is an example:
I have a graph that looks like this:
100 ——
|
|
50 ——
|
|
0 ——
I want it to look like this:
50 ——
|
|
|
|
|
0 ——
Notice that there is actually one less tic in the after sample.

The distance between tics is set by set xtics or set ytics command. For example if I use the command plot sin(x)
then the space between the xtics is 5 by default. The command
set xtics -10,2,10
replot
makes the xtics appear at an interval of 2. In the above command the format is
set xtics <start>, <increment>, <end>
See help xtics inside gnuplot for details.
Hope this helps!

As suggested in another answer by andyras (Change actual space between tics in gnu plot) you can do it by controlling the size of your terminal.
I also had a problem, where I wanted the tics in the axis to have the same distance in absolute values (though I don't know the value itselft, but the grid should be quadratic in the end).
So if you want a quadratic grid/spacing of your tics, put
set terminal pdfcairo size 100, 100
For rectangular put
set terminal pdfcairo 100, 200
and so on.
Again, this is an answer suggested by andyras, not me. I took his answer, which worked for my case.

Related

Spurious '-' text with epslatex and multiplot

The following gnuplot snippet generates a multiplot showing six plots of data ported via stdin, but the special filename '-' used is also printed on the output:
set term epslatex color
set output 'mwe.tex'
set multiplot layout 3,2 scale 1,1 columnsfirst
set xrange [-3.1415:3.1415]
set yrange[-1.0:1.0]
set cbrange [-1:1]
set size ratio -1.0
set palette rgb 33,13,10
unset colorbox
plot '-' with image
-3.1416 -1.00 0.00
-3.1089 -1.00 0.00
(...)
e
(...)
unset multiplot
(The 'plot' command and what follows until and including 'e' is repeated six times with different input before the unset multiplot command.)
The output is shown here. The special filename '-' must be included in the plot command to plot inline data, but it should not be shown in the resulting plot. How to avoid this behavior?
The problem persists when using the 'standalone' term option with epslatex, but it does not show up when using other terminals.
I use gnuplot 4.6 patch 2.
According to the StackOverflow rule "no answer in the comments", here again as answer. Also check help key and the options there.
Try:
set key noautotitle
or
plot '-' with image notitle

gnuplot: why is linewidth 0 not zero in width?

What is the reason that lw 0 doesn't have zero linewidth, i.e. invisible?
What I find in the gnuplot manual:
The line width and point size are multipliers for the current
terminal's default width ...
Ok, if lw 0 is a multiplier then the resulting linewidth should be zero independent of the terminal's default linewidth.
The reason for asking is to eventually have the possibility to use with linespoints and programmatically switch within a loop between with lines and with points.
Code:
### linewidth 0 isn't zero
reset session
set key out
set yrange[-0.9:10.9]
set ytics 1
plot for [i=0:10] i with lines lw i title sprintf("linewidth %g",i)
### end of code
Result:
By the way, what are the artefacts at the y-axis e.g. at ytics 3,4,6,7,9,10 (wxt-terminal)?
Mike Nakis is correct that for at least some of the gnuplot output terminals, including PostScript, gnuplot asks for a 0 width line and the language or library in question interprets that as "1 pixel" or "thinnest possible line".
Similarly "pointtype 0" is not truly missing, it produces a single pixel dot.
You can, however, disable the line drawing altogether by using linetype "nodraw".
That gives a complementary pair of commands
plot sin(x) with linespoints lt nodraw pt 7 # only the points are visible
plot sin(x) with linespoints lt 1 pt 0 # only the lines are visible
In some circumstances it may help to know that the numeric equivalent for lt nodraw is lt -2.
I don't know for sure what the official explanation is for gnuplot in particular, but in my experience, most graphics packages / tools / libraries etc. use a special convention for a line width of zero.
According to this convention, a line width of zero does not mean invisible; it simply means "the thinnest line possible". This means the thinnest line that can be displayed on the device, regardless of zoom, transformations, logical-to-physical mapping, etc.
So, on monitors, it will be a line which is one pixel wide.
On a printer, it will be the thinnest line that the printer is capable of producing. So, if the printer has a high enough resolution, then the line might practically be invisible, though a magnifying glass should still be able to reveal its existence.
And note that "regardless of zoom, etc." means that even if you set up some scaling that makes your 10-point line look as thick as 100 pixels, the zero-width line will still be exactly one pixel thick.

Gnuplot: Change Density of dotted line in splot

I am trying to plot a dotted line within an splot with the following code in Gnuplot 4.6 patchlevel 4:
set terminal "pdfcairo" enhanced dashed size 15,10
set pm3d map
set output "test.pdf"
splot 'map.dat' using 1:($2/1000):3 notitle, \
'line1.dat' using 1:($2/1000):1 notitle with lines ls 2, \
'line2.dat' using 1:($2/1000):1 notitle with lines ls 2
unset output
The heat map works and so does line1.dat. However, the second line appears mostly solid. The difference is that line1.dat has 70 entries and line2.dat has 900. The second line has a jump between two points and there it is dotted.
Does somebody know how I can change the dot density so that the whole line appears dotted. Changing the original data file is not an option.
Thank you for your help,
noes
EDIT:
One workaround I found is
splot 'line2.dat' every ...
but that can get unconvenient at the jump in the data.
The command (s)plot 'line.dat' with lines first plots the datapoints and then connects the datapoints using lines with the respective linestyle. If the datapoints are too close to each other, there is no place for some gaps when a dashed linestyle is used.
To display a dotted/dashed line, you can try to replace the points by a function or to reduce the number of points.
Try dotted lines instead of dashed lines. Linestyle and linecolor can be set independently: splot 'line.dat' with lines ls 0 lc 2. 900 points might be too many for this approach.
Fitting a function would work, but probably it is too difficult to find a suitable function.
The every option reduces the number of points.
Another possibility to reduce the number of points would be to interpolate the points using the smooth option. This requires a temporary file and works as follows:
# [prepare plot]
set samples 100
set table "line2.dat.tmp"
plot 'line2.dat' using 1:($2/1000) smooth mcsplines with lines ls 2
unset table
set terminal "pdfcairo" enhanced dashed size 15,10
set pm3d map
set output "test.pdf"
# [plot]
splot 'map.dat' using 1:($2/1000):3 notitle, \
'line1.dat' using 1:($2/1000):1 notitle with lines ls 2, \
'line2.dat.tmp' using 1:2:1 notitle with lines ls 2
unset output
In the [prepare plot] section a temporary file "line2.dat.tmp" is created which contains datapoints interpolating line2.dat. You have to play with set samples to get the right number of points. In the example we have 100 equidistant points instead of 900 points with different distances.
The option smooth mcsplines preserves the monotonicity and convexity of the original data points, see help smooth mcsplines in a gnuplot shell.
In the [plot] section the original "lines2.dat" is replaced by the interpolated data.
This approach works if the original data is smooth enough so that replacing 900 points by 100 points does not skip important information. Maybe you want to plot both "lines2.dat" and "lines2.dat.tmp" in a single diagram to compare them.
User the every key-word, like this:
'line2.dat' every 20 using 1:($2/1000):1 notitle with lines ls 2

Gnuplot: trailing white space

I've got a multiplot like this:
How do I remove the trailing white space added by the xtics interval? Relevant configurations include:
set xtics 10
set mxtics 5
Data for the xaxis goes up to somewhere between 135 and 140.
Thanks.
You have to set your xrange explicitly if the data do not end at some nice round value. One way to do this is to use the stats command (gnuplot 4.6.0) and up:
stats 'data.dat'
set xrange[STATS_min_x:STATS_max_x]
Otherwise you can set xrange manually (if you know the value), or use the old-fashioned method:
set output '/dev/null'
plot 'data.dat'
set xrange[GPVAL_DATA_X_MIN:GPVAL_DATA_X_MAX]
set output'actual_output.png'
replot
To disable the automatic extension of the autoscaled x-axis to the next tic mark use
set autoscale xfix
The general syntax is
set autoscale {<axes>{|min|max|fixmin|fixmax|fix} | fix | keepfix}

Gnuplot - Using replot with png terminal

I am trying to use replot with png terminal in Gnuplot.
If I do the following I get two plots on one graph without any problem:
plot sin(x)/x
replot sin(x)
Now if do the same for a png terminal type the resulting png file only contains the first plot.
set terminal png
set output 'file.png'
plot sin(x)/x
replot sin(x)
Am I missing something at the end to get the second plot in my png file?
This is actually a very good question, and the behavior here is terminal dependent. Some terminals (e.g. postscript) will give you a new page for each replot. You have a couple of solutions...
First Option: You can make your plot prior to setting the terminal/output and then replot again after you set the terminal/output:
plot sin(x)/x
replot sin(x)
set terminal png
set output 'file.png
replot
This option is sometimes convenient if you want to plot the same thing in multiple terminals, but I rarely use it for anything else.
Second (better) Option: You can pack multiple plots into one command separating each with a comma.
set terminal png
set output 'file.png'
plot sin(x)/x, sin(x)
I very much prefer the second way -- when in a multiplot environment, this is the only way to put multiple graphs on the same plot. If you have very long functions to plot, you can break the line with gnuplot's line continuation (\ at the end of the line -- Nothing is allowed after the \, not even whitespace)
plot sin(x)/x with lines linecolor rgb "blue" linetype 7 lineweight 4, \
sin(x), \
cos(x)

Resources