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

Related

Plotting smooth sphere from discrete data with gnuplot

I have data generated from python code as such:
u, v = np.mgrid[0:2*np.pi:180*1j, 0:np.pi:90*1j]
X = np.cos(u)*np.sin(v)
Y = np.sin(u)*np.sin(v)
Z = np.cos(v)
This is written to a file tmp.dat, and I attempt to plot it in gnuplot with:
set pm3d
set palette
set hidden
splot "tmp.dat" using 1:2:3 with pm3d
However, this gives me:
It's in the general vicinity of what I want, but I'd like a smooth sphere as opposed to this. (My real data is in the same vein; with an enclosed surface I want to have transparency on.) I've tried adding set dgrid3d 50,50 to try and interpolate, however, I don't actually understand what I'm getting from this:
Any help or advice would be enormously appreciated. Changing the data to parametric (with u and v sweep data) is an option, however, I'm not certain how to do that - when I tried, the result was the same.
Not a complete answer, but part of your problem is that "set hidden3d" is not usable here. Gnuplot has two separate subsystems for representing surfaces. One of them, controlled by "set hidden3d", tracks bounding line segments and can remove occluded portions. The other is pm3d, which uses solid-fill quadrangles rather than bounding line segments. pm3d plots do not have the option of removing occluded quadrangles, but you can get a similar effect by depth-sorting them. The relevant command is
set pm3d depthorder
This works reasonably well if the individual quadrangles are approximately square but it gives bad results for long thin quadrangles, since the two ends of the facet can have conflicting depths with regard to neighboring facets.

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.

Gnuplot key opaque background

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.

Improving gnuplot 3d plots from data files with pm3d

I'm trying to graph an approximate solution (finite element method) to the Navier-Stokes equation. I've got a file called plotNSu1 that looks like this:
6 1 4.21022e-34
5.95 1 8.15227e-34
5.9693 0.970854 0.055197
6 1 4.21022e-34
5.9693 0.970854 0.055197
6 0.95 0.0941333
6 1 4.21022e-34
5.9693 0.970854 0.055197
5.92625 0.951192 0.0915468
5.9693 0.970854 0.055197
5.95 1 8.15227e-34
5.92625 0.951192 0.0915468
...
(The entries are x y z, grouped so that there's a blank line between each set of 4 points).
I use the following command to plot:
splot "plotNSu1" with lines
Butt I would like to make it look nicer, easier to read. (There's a small dip at one spot that's difficult to see, but is an important part of the solution).
I've found lots of examples using pm3d interpolate, but none seem to work for me. I've tried set style pm3d, and other set style commands, I've tried set pm3d map interpolate 10,10, and splot "plotNSu1" with pm3d, as well as so many other similar things stolen from the examples I've found that I can't keep track. Most of the time I just get an empty window with the color key and no plot, and often it sends me an empty 2d window.
I would like to have the color change with the contour of the plot, to make the little dip easier to see. Does anyone know how to do this? Here's one of the websites I've been trying to use, to see what I'm aiming for: http://gnuplot.sourceforge.net/demo/pm3d.html
I tried to post the image, but as I do not have enough reputation, I can't. But it's difficult to see what's going on because the graph is just all red.
I found a way to make this work, more or less, thanks to #Christoph's help and this other question suggested by stackoverflow: gnuplot pm3d plot triangle data
With my data in the file described above, in gnuplot I type:
set dgrid3d
set pm3d corners2color c2
splot "plotNSu1" using 1:2:3 with pm3d
The result isn't perfect, it looks a little choppy, but it basically does what I wanted, I can see the "dip" in my graph much better now.

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.

Resources