How increase the size of the legend in Gnulot - gnuplot

Can someone please direct me as how to increase the size of a legend in Gnuplot.
I wish to place the legend outside with:
set key outside top
But now I want the legend to appear larger in size. How can this be done?

The font specification can follow the setting of key, from help key:
{font "<face>,<size>"}
You do not need to specify the face if you only want to change the size, e.g. to set font size to 16 do this:
echo 'set key outside top font ",16"; plot sin(x) w l' | gnuplot --persist
Which fonts are available depends on the terminal setting, e.g. if your terminal is wxt, you can find out more by running help wxt, etc.

Related

Gnuplot key: sample and title positions

Is it possible to adjust the relative vertical position of the sample in a key
and its title? Running these commands
set terminal pdfcairo
set output 'foo.pdf'
set yrange [-1.2:1.2]
plot sin(x)
produces a plot with a key that looks like this:
I'd like the sample in the key to be a bit lower relative to the title in the key (or the title in the key a bit higher relative to the sample in the key).
EDIT: There seem to be other issues with alignment, not just in the key. This is the whole graphic produced by the commands above, using the latest Gnuplot installed by homebrew on OSX 10.10.5 (Gnuplot 5.2.2, cairo 1.14.12). The same thing is evident on OSX 10.11.6. At least some of the labels on the xaxis seem to be shifted a bit to the right of the tic, and labels on the yaxis seem to be shifted down.
help set key provides you with all necessary details. In your case, probably
set key left
would already help. But there is also the option to tell gnuplot precisely where you want the key to be placed, using
# This places a key at coordinates x = 6.5 and y = 0.8 in the coordinate system:
set key at 6.5,0.8
Another way, rather than playing around with key positions, is also to adjust the range in a way that comfortable space is left for the key, in your case
plot [-10:+10][-1.1:1.2] sin(x)
might help.

Using gnuplot with a hidpi screen.

I am using gnuplot on a hidpi screen (276 dpi).
The plots I recover are hard to see properly, the lines too thin, the fonts and buttons too small.
Is there any way to configure gnuplot to scale up these parameters for hidpi screens automatically upon start?
gnuplot automatically loads an initialisation file on startup, that you can use to change the default linewidths etc. It accepts normal gnuplot syntax. Check help initialization to see how it's named and where to place it on your system.
Use e.g. set terminal wxt lw 2 to change the absolute default linewidth. The sizes given in a later plot command are just multiplicators for the terminal setting. The pointsize and border/tics linewidth are scaled accordingly.

Consistent figure sizes with gnuplot

I am trying to make figures with gnuplot that will be included in a latex document. I want all figures to have the same dimensions and font size. To achieve it I found that I should specify the size of the figure in advance, which I do as such:
set terminal postscript eps size 3.4004,2.104 enhanced color
However, the resulting .eps figures have a lot of whitespace around them so I use the fixbb script to remove all unnecessary space. This changes the final size of the figure as well, which wouldn't be a problem as long as it is consistent. However, the amount of whitespace seems to vary from figure to figure, so my final figures have all different sizes.
This seems especially a problem with 3D plots.
Is there a way to make the size consistent while removing all unnecessary white space? In matplotlib there is the plt.tight_layout() command which does exactly that.
If by fixing the size of the figure you refer to the rectangle within which the data is plotted, you can set the margins manually. What I usually do for figures I put on my papers is use the epslatex terminal with the desired size and font, then set the margins, and then compile to pdf followed by a cropping to remove the white space. Example
set term epslatex color size 3.5,2.5 font 6
set output "gnuplot.eps"
set lmargin at screen 0.2
set rmargin at screen 0.98
set tmargin at screen 0.98
set bmargin at screen 0.1
plot sin(x) title '$\sin (x)$'
I embed this into a .tex file (which I call plot.tex):
\documentclass{article}
\usepackage[papersize={100cm,100cm}]{geometry}
\usepackage{graphicx}
\usepackage{color}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage[mathcal]{euscript}
\begin{document}
\thispagestyle{empty}
\include{gnuplot}
\end{document}
And run the following:
pdflatex plot.tex
pdfcrop plot.pdf
You will have a plot-crop.pdf with no white space around. Using different modifications of the above you can very precisely modify the size of your graph.
Finally, note that the epslatex terminal also allows the standalone option to avoid needing an external latex document to wrap your graph.

force graphs legend/key to a specific size

i want to generate some plots from my data that i want to include in some documentation.
I put the box outside the graph area.
the problem is that for different plots the box has different sizes so also the graph area changes its size. this looks very messy in the document becasue the plots are vertical aligned.
I am searching for a way to fix the size of the box to some width that is appropriate for all plots but i could not found a way to do so.
the set key command has a width parameter but it seems not to do that one would expect from such a parameter.
It would be grat if someone could help.
thanks
vlad
I hope I got the correct impression of what you want. Consider the following example
reset
set multiplot layout 2,1
set rmargin screen 0.7
set key reverse Left left top at screen 0.72, graph 1
plot sin(x), cos(x) t 'long title'
plot sin(x), cos(x) t 'very long title'
unset multiplot
Which gives you:
Both the samples and the text do not move. You must only set an appropriate rmargin. left and top is the key box alignment regarding the position specified with at ..., although these settings are default, I explicitely included them for clarity. Left is the alignment of the entry text.

How to make plots larger in GnuPlot

I am generating mapped 3D plots using the following config file (XRANGE and YRANGE are set later)
#!/usr/bin/gnuplot
reset
set term postscript eps enhanced
set size square
set xlabel "X position"
set ylabel "Y position"
#Have a gradient of colors from blue (low) to red (high)
set pm3d map
set palette rgbformulae 22,13,-31
set xrange [0 : XRANGE]
set yrange [0 : YRANGE]
set style line 1 lw 1
unset key
set dgrid3d 45,45
set hidden3d
splot "data.data" u 1:2:3
The resulting image looks something like this
Note: I have converted to jpg so the quality is lower, and I have placed a border around the image.
A great deal of space is wasted above and below. This is not a problem until I embed the image into a LaTex document, at which point it will look like so (again, pdf document converted to jpg image)
The image on the right is also created with GnuPlot, but it is slightly larger (as is evident by looking at the border I have drawn around the top two images). The reason for this is because GnuPlot pads the 3D plot with top and bottom white space. How can I remove this without having to manually edit all 50+ plots I have?
There are two solutions to this, one is unreliable, the other is a hack.
Using GnuPlot, the margin settings can be used to specify distances from the appropriate margins. For example, setting lmargin 0 and bmargin 0 essentially pushes the axes off the page. Similar values can be assigned to the tmargin and rmargin to stretch the graph. Although this worked for 2D graphs, it did not work for 3D graphs (I suspect this has to do with the fact that I set the graph to be a square).
When graphs are set to be of square size, Gnuplot still calculates for the entire screen. The eps file can be manipulated directly to change this by looking for a line like so %%BoundingBox: 50 50 410 302 and changing 410 to something smaller. Alternatively, and this is what I did, you can run eps2eps in.eps out.eps and it will crop it for you. Just make sure in.eps is not the same file as out.eps or it won't work.
I also crop the Bounding Box afterwards, since I hate playing around with margins in gnuplot. I realized that somehow, eps2eps indeed does adjust the bounding box, but it also transforms text (labels etc) into pixel-graphic?!
I usually use "epstool" which conserves text as text when croping the bb, the command I use is:
epstool --copy --bbox in.eps out.eps
Use the <scale> argument in set view, this will magnify the plot without changing text size or title position.
In your case, because you use the map view, you need:
set view 180,0,1.5
where 180,0 is equivalent to map view and 1.5 is the scaling factor.

Resources