Gnuplot key opaque background - gnuplot

I am trying to move the legend of a plot in gnuplot partially outside the plot area. It seems however that the plot border is visible inside the legend, even if I set the legend property to opaque.
A minimum example showing the problem:
#!/usr/bin/gnuplot -persistent
set key at 11,1.02 box opaque
plot sin(x)/x
So, I wonder how I should go about in order to make the entire interior of the key opaque white? I've thought about putting a white rectangle behind it, but it seems to be a kind of dirty solution.

The opaque option of the key does indeed draw a white rectangle, but the border is drawn on top of the key. Use set border back to draw the border behind the key:
set key at 11,1.02 box opaque
set border back
plot sin(x)/x

There isn't an option to set the key color directly; people tend to resort to either drawing a box under the key (as you were thinking) or more complicated methods.
One workaround is to get rid of the plot border for the top and right edges of the plot (since the information there is redundant anyway):
set border 3
set tics nomirror
plot sin(x)/x
Another possibility is simply moving the key--does it need to be right on the edge of the plot? It could be further inside or outside.

Related

How to apply beatiful fading edge occlusion on Gnuplot's splot function?

Hello fellow stackers,
So I am a gnuplot afficcionado and I keep trying to use gnuplot to draw all sorts of things (including molecules) using it. These days I decided that it would be awesome if I could draw polyhedran in it with this beautiful thining-edge occlusion effect that we see in the interactive javascript polyhedral images here. See how the backside of the polyhedron is drawn differently from the front side and how they change dynamically as you rotate the solid? How can I do that in gnuplot?
I agree that is a really nice representation. Gnuplot cannot currently do the equivalent of "draw the inside edges using thinner lines", but the combination of partial transparency and using the background color as the fill color for the faces creates almost the same effect.
# Generation of polyhedral vertices and faces not shown.
# Each face is an object of type polygon, e.g.
# set object 1 polygon from ... to ... to ...
# make all the faces semi-transparent
set for [i=1:20] object i fillstyle transparent solid 0.6 fillcolor bgnd border lw 2
# use pm3d depthorder sorting to render the objects
# NB: gnuplot version 5.3 required
set for [i=1:20] object i polygon depthorder
set xrange [-2:2]; set yrange [-2:2]; set zrange [-2:2]
set view equal xyz
set view 30,30,1.5
unset border
unset tics
unset key
unset label
splot NaN
Results shown below for a cube and for an icosahedron. You can rotate them interactively as with any other splot.

How to place labels on top of the margin?

I am using gnuplot with epslatex terminal. I want to know how to put the
label on top of a margin, so that the part of margin under the label is invisible. In the figure I attached, the part of margin under the label
is still visible.
In principle you should be able to tell gnuplot to put your text labels into a box by using the set label ... front boxed, and the specify that the box should be opaque and white using something like set style textbox opaque noborder fillcolor rgb "white". However, this is not supported by all terminals, and epslatex seems to be one of those where this doesn't work.
However, in epslatex you can simply use latex commands to create a white background box around your label text:
set term epslatex standalone
set outp "test.tex"
set label "\\colorbox{white}{This is a label}" at 6.,0.5 front
plot sin(x)
set output
gives

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 can I blank out the background of the key in gnuplot?

My plot is covering up my key in gnuplot. What I'm plotting oscillates a lot, so there's nowhere on my plot I can go and not interfere with something. How can I give the key an opaque background so that the items inside aren't covered up by lines?
My version of gnuplot supports opaque keys via:
set key opaque
Try out the following:
set key box opaque
plot sin(x)
Another option in cases like these is to move the key outside the plotting area:
set key outside
plot sin(x)
This way you don't obscure any of your valuable data.

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