gnuplot: floating terminal width ? fixed terminal height - graph

Can you tell us how to make the chart with all headings and captions fit into the fixed vertical size and the horizontal size is floating?
If I set small fixed image sizes, some axes captions disappear, and if I set large fixed image sizes, then there is an empty space on the sides.
And I want you to be able to specify the height of the image and gnuplot will determine for itself what its width must be to fit everything you need.
For example (margin - empty space, but on the right, the inscription didn't fit:
set terminal pngcairo notransparent enhanced font "Calibri, 15" fontscale 1.0 size 800, 800; set zeroaxis;

Apparently, gnuplot does not automatically provide enough space for long numbers in the colorbox.
Since you have a logarithmic scale from 0.0000001 to 0.1, you might want to consider to display your numbers in a different format, i.e. from 10^-7 to 10^-1.
Code:
### no long numbers in colorbox
reset session
set colorbox
set palette rgb 33,13,10
set xrange [-7:-1]
set cbrange [1e-7:0.1]
set logscale cb
set format cb "10^{%T}"
plot '+' u 1:1:(10**$1) w l lw 3 palette z notitle
### end of code
Result:

Related

How do gnuplot margins work in multiplot mode?

I am a bit confused about gnuplot margins. First of all I have no idea what units these things are pointing to. Are they pointing to the canvas coordinates OR are they a fraction of the canvas coordinates. Do they behave the same in gnuplot mode and multiplot mode?
My problem arises when plotting some data in multiplot mode. I am plotting to the screen (wtx terminal). Let's just say I am bungling things badly - I get plots off the canvas, or very small unreadable plots.
Without margins the first plot is flush against the top of the canvas, so naturally I want to push it down a bit.
Can someone explain how gnuplot margins work and if they behave the same in multiplot mode.
Yes, the margins behave very similar in "normal" plotting mode and in multiplot mode. Basically, the margins can have three different "modes":
Automatic, which is the default.
Setting each margin to a specific size, like set lmargin 2. The unit is character widths (or character heights for tmargin and bmargin).
Setting a specific position of a border relative to the whole canvas, like set lmargin at screen 0.1, which sets the left plot border at 10% of the total canvas width.
The only difference of the multiplot mode is, that the reference for the margins in 1. and 2. is given by the sites determined by the layout option:
set multiplot layout 2,2
This subdivides the whole canvas in four rectangles of equal size. Now, using
set lmargin 1
set rmargin 1
set tmargin 1
set bmargin 1
leaves a margin of one character width or height on each side of each subplot with respect to the smaller rectangles:
set multiplot layout 2,2
set lmargin 0
set rmargin 0
set tmargin 0
set bmargin 0
set format ''
plot x
plot x**2
plot x**3
plot x**4
unset multiplot
set multiplot layout 2,2
set lmargin 1
set rmargin 1
set tmargin 1
set bmargin 1
set format ''
plot x
plot x**2
plot x**3
plot x**4
unset multiplot
If you want to set absolute positions of each border, this becomes more cumbersome, because you have to set four margins for each plot (the layout options doesn't have any effect in this case):
set multiplot
set lmargin at screen 0.1
set rmargin at screen 0.47
set tmargin at screen 0.97
set bmargin at screen 0.6
plot x
...
Gnuplot version 5 offers a quite flexible way to produce equal rectangles, see my answer to Removing blank gap in gnuplot multiplot

Gnuplot 3d plotting --- making plot size set to terminal size

Okay I have been working with gnuplot for sometime and have one question. I cannot make the plot size equal to the terminal size I set it to. There are examples of setting
Lmargin,rmargin, tmargin and bmargin to 0 but this doesn't work on 'splot' which is 3d plotting. So I want to know what is the workaround for it?
For color maps you can use plot ... with image instead of set pm3d map if you want to use the margin options as usual. For 3d plots, as you say, the margin options are not available, and a workaround would be to shift the position of your graph and scale it. To do that, use set origin and set size respectively.
For instance, splot x*y yields the following:
If you want to reduce the margins while keeping the same overall terminal size, you can try:
set origin -0.1,-0.1
set size 1.2,1.2
splot x*y
which gives you:
You probably get the idea. Note I set a background color just so you can visualize where the margins lie because of the white background in the Stack Overflow website.

Missing label when converting eps to pdf

I use the following gnuplot script in order to plot a data file
reset
unset key
set size 1,1
set xrange [-10.1:11]
set yrange [-45:45]
set xlabel 'x'
set lmargin 6
set label 1 "~x{0.7.}" font "Helvetica, 20" at graph -0.1, graph 0.5
set xtics 2
set ytics 15
set mxtics 5
set mytics 5
plot "pss_data.dat" u 1:2 w dots lc rgb 'black'
set term postscript eps enhanced "Helvetica" 20 size 7in, 5in
set output 'plot.eps'
replot
reset
set terminal windows
quit
The exported .eps file is the following.
Well, in fact this is the corresponding .pdf file using Adobe Acrobat XI in order to make the conversion. However, the .pdf output contains not only the plot but all the unwanted black area above it! In an attempt to get rid off the white area I used the command line
epstopdf plot.eps
The output is the following
Now, the white area has been removed but the label at the y axis is also missing!
Any ideas? I want to have in a .pdf file only the plot (without the above white area) but with the label at the y axis.
Many thanks in advance.
Your bounding box may be incorrectly set. You can try using epstool on the eps you create:
epstool --bbox myeps.eps myneweps.eps
That should calculate the bounding box correctly, but give you a margin of zero. If you can't/don't want to install it, try adjusting the bounding box manually. There is a line near the top of the .eps file which looks like this:
%%BoundingBox: 50 50 554 770
The four numbers are the y offset, x offset, y max and x max of the output (in terms of margins you can think of them as top, left, bottom, right). You can try decreasing the second number (increasing the left margin) to see if that reveals your y axis label.
I would avoid the conversion all together by using one of gnuplot's pdf terminals (I like pdfcairo) and just use ylabel instead of set label 1 ... at graph.... Here's a simple script that you can modify for your purposes:
set term pdfcairo enhanced font "Helvetica,20"
set output "test.pdf"
set ylabel "~x{0.7.}" rotate by 0 #default rotation is 90
set xlabel "x"
plot sin(x)
Ultimately, what is happening with your script is that gnuplot is putting the label off of the viewable canvas. Some reason adobe still puts the label on the (converted) output, but I would assert that they are wrong in this case -- (they're essentially ignoring your bounding box). Of course, you could move/adjust the bounding box as suggested in the answer by andyras -- but I would argue that is a pretty hacky solution.

Gnuplot: add key outside plot without resizing plot

In gnuplot, I can put the key outside the plots using this command:
set key outside;
set key right top;
But as this page indicates, the placement of the key will automatically resize the plot area such that the size of the resulting image remains the same. Is there an easy way of keeping the plot area the same no matter where I place the key outside the plot area?
The size of the plot in units of the canvas size is set with the "set size" command. But
the key is considered part of the plot, so the actual graph will always shrink when you use "set key outside", so that the graph + key obey the size that you set with "set size".
What you need to do is first make room for the key by shrinking the plot horizontally, say by "set size .75, 1". Then position the key manually. Rather than saying "set key outside", try "set key at x,y", where x and y are in your axes units. The value of x will be some margin + key length + x-axis length, and the value of y will be somewhat less than the top of your y-axis. You will want to experiment a little to get the placement that you like, but you will find that the graph size does not change as you move the key around using this command.
Old question but an easy solution is to simply set a rmargin and place the legend inside it. Example:
f(x) = x
g(x) = x**2
set multiplot layout 2,1
set rmargin 30
set key at screen 1, graph 1
plot f(x) title "Legend 1 blablabla"
plot g(x) title "Legend 2"
unset multiplot
You only need the margin to be big enough for your legend. Default unit is the character width.

gnuplot: how to set plotting area to be a pixel perfect representation of data

I'm having difficulty getting GNUplot to properly render some of my data. Basically I have some 2D heightmap data (for example 512 x 128 data points) and would like to be able to plot this in a "pixel perfect" fashion (i.e. one pixel per data point). Unfortunately at the moment, I'm getting artefacts (see inset) due to the number of pixels being slightly larger than the number of data points. I know I can set the total size of the output using:
set terminal png size 800,400
but is there a way to set just the plot area size in pixels?
Thanks!
From the help of the lua/TikZ terminal (there is an option plotsize) it is suggested to remove the plot margins so that plot fills the whole canvas.
set lmargin 0
set rmargin 0
set tmargin 0
set bmargin 0
set terminal png size 512,128
set out 'out.png'
# a checkerboard pattern to test the plot results for errors
f(x,y)=( (x<=0) || (x>=63) || (y<=0) || (y>=63) ) ? 0.5 : ((x+y)%2==0)?0:1
# the 'map' file contains only coordinates.
plot[-1:63][0:64] 'map' u 1:2:(f($1,$2)) with image
unset out
However, this has the drawbacks that you will not have tic labels and so on. You can of course calculate values for the margins yourself, so that they match with the plot size in the end: use
set lmargin at screen 0.25
for example.
Anyway, I would also recommend going for vector graphics whenever possible.

Resources