I'm am plotting multiple variables in gnuplot. I would like to centre the key under the plot, and centred on the plot area.
My current settings are:
set key outside
set key bottom center horizontal
This centres the key across the entire width of the plot. I would like to centre the key across the extent of the x axis; ie align it with the xlabel.
Is this possible in an automated fashion, or is tweaking involved?
Edit: This is all my mistake. I had asked gnuplot to plot a file that wasn't there, so its key was empty, but the space for it was still there, and that threw off the "alignment"; it was aligned with three entries, but not for the visible two.
Depending on which arrangment and alignment you are looking for...
also check help key for more options.
reset session
set multiplot layout 2,1
set xlabel "This is the xlabel"
set key outside bottom center vertical
plot sin(x), cos(x), sin(-x), cos(-x)
set key outside bottom center horizontal
replot
unset multiplot
Related
since my last post I tried cleaning up my code a bit and am almost done with the plot. The only thing left to do is splitting the key of the first plot into two parts. One being the titles of the graphs and the other one being the time that data was captured. The title should go top left while the time should go top right.
The code:
set key top left title '0 s'ยด
set ylabel 'Konzentration'
set format y '%g'
set ytics border out nomirror 2
set mytics 2
plot 'data/paper_2_csv_a_0000.csv' using 3:1 axes x1y1 with lines ls 1 title 'Aktivator',\
'data/paper_2_csv_h_0000.csv' using 3:1 axes x1y1 with lines ls 2 title 'Inhibitor'
;
produces the output
So how can I move the "Aktivator" and "Inhibitor" part to the left while leaving the "0 s" where it is right now?
There are several titles:
a title of a plot, check help title
a title of a legend/key, check help key, option title
a title of a multiplot, check help multiplot, option title
I guess you want to separate the key title and move it to the other side. I guess that's not possible.
Probably the easiest is to place a label. You place it e.g. at a position relative to the graph (here: 0.95,0.95) and the text alignment at that position is right. Check help label.
Labels are persistent (e.g. in a multiplot environment), so don't forget to set unset label 1 or overwrite it with another title for the next multi(sub)plot.
Script:
### place a label/title
reset session
set key top left
set label 1 "0 s" at graph 0.95,0.95 font ",12" right
set offsets 0,0,0.2,0.2
plot sin(x), cos(x)
### end of script
Result:
How can I place the key some distance from a given border? For instance if I run set key below I can place the key below the graph, but it's too close and actually overlaps the xlabel. How can I place it some distance further, something like set key below 1 to put it 1 below the default below position?
To clarify, I know I can place it manually with set key at x,y, but that involves manually looking for the right place. This requires manual calculation and adjustment to, for example, get it centered. I just want to put it a bit below its default below position.
You could add a little extra height to the legend so that there is effectively more space between the bottom border of the plot and the legend content:
set key below height 2
set xlabel "this is the x axis label"
plot sin(x)
gives
Multiplot scale
I don't really understand the idea behind the scale option in the multiplot command of gnuplot.
set multiplot layout 2,2 scale x,y
There can be only one pair of values for the whole multiplot - what is it possibly used for? Is it really just for scaling all the graphs in the multiplot? What for?
It would make sense to me, if you could assign scale factors the the individual layout parts, in that I would say: first column takes 70% of the width, second column takes 30% etc but here?
I'd appreciate any explanation! Plus, is there a built-in function to generate multiplots using the "layout" option in the described manner?
Multiplot Layout
I want a multiplot layout consisting of a 4rows,2columns grid. Both columns should fill 45% of the space each, leaving a 10% white gap at the right which will be used for a label set right next to the second column via set label at graph 1,0.5 "text". (Actually, this means a 45% / 55% ratio of the two columns.)
This works with this MWE
set multiplot
mystring = "This is\na multiline\nlabel"
width = 0.45
height = 0.25
#1 1
set origin 0,1-height
set size width,height #remains the same
plot sin(x)
#1 2
set origin width,1-height
set label at graph 1,0.5 offset 2,1 mystring
plot cos(x)
unset label
#2 1
set origin 0,1-2*height
plot sin(x*2)
#2 2
set origin width,1-2*height
mystring = "This "This is\na different\nlabel"
set label at graph 1,0.5 offset 2,1 mystring
plot cos(x)
unset label
#etc...
unset multiplot
However, I want to put some labels (no title etc) above the first row. If I make space via set tmargin <val> for the first row, then the plots get squished, not shifted. Is there a way to somehow "add whitespace" around the plots, the top in particular? Or would I need to make the height variable a tad smaller and adjust accordingly?
Plus, I made no size settings, as you see, but used proportionals in the range of [0,1]. When using the epslatex terminal, I'll provide overall size information. Can I expect the ratios to preserve?
I'm trying to plot two data sets with gnuplot. They are both (x, y, z) triplets. They are not arranged on a grid. I want to plot one of them using dgrid3d and pm3d. On top of that I want to overlay the other data set but as just scattered points.
To give a more concrete example: I am trying to plot the effect of a cylinder approaching a surface. I want to plot the response of the surface and that's where dgrid3d comes in handy. On top of that, I want to plot the position of the cylinder and I have its circumference as points.
I used:
set dgrid3d 100,100,4
set pm3d
splot "dataset1" with pm3d, "dataset2" with dots
The data set has about 100x100 points, arranged on a near-square, so 100,100 works best here. No matter how I plot the second data set, it always ends up being a square of the same dimensions as the cylinder, instead of a nice circle. When I turn dgrid3d off, I can plot the second data set on its own and the result is a nice circumference of the cylinder.
So my question is: is it possible to plot a 3D graph using two data sets, one using dgrid3d and the other one not using it?
Yes, this is possible, but it is a little more tricky than you might think. The key is to use set table
For your example:
set dgrid3d 100,100,4
set pm3d explicit
set table "interpolated_data.dat"
splot "dataset1" with pm3d #writes the interpolated data to "interpolated_data.dat"
unset table
unset dgrid3d
splot "interpolated_data.dat" with pm3d, "dataset2" with dots
The reason that your attempt didn't work is because when dgrid3d is in effect, All data read in is interpolated to a grid and then plotted using whatever style you specify.
From gnuplot's help dgrid3d
When enabled, 3D data read from a file
are always treated as a scattered data set.
As a side note, this method can also be used to plot contours on top of a pm3d as well.
I am new to gnuplot and while plotting stacked histogram, I find that legend gets hidden behind the data.
Is there a method to put the legend above the data? Thanks a lot for your help.
EDIT: I am currently using set key outside bottom to place legend outside, but that is not the best solution I would like.
Recent versions allow to make the background of the legend white:
set key opaque
This simply adds a white background to the legend so it appears on top of all graphs. Found the answer in this Post.
If you would rather have the key on top of the data rather than the key outside the plot box altogether, here is one workaround (using sin(10*x) as an example):
set multiplot
unset key
plot sin(10*x) # this will plot with tics and a border, but no key
set key box
unset tics
unset border
bignumber=10 # make this number larger than the y range so the line will not be seen
plot [][0:1] bignumber title 'sin(10*x)' # this will just plot the key with the title
unset multiplot
Using this method, first you plot your data/function, then you create a plot on top of that which just has a key. You have to make sure to set the title of the second plot properly.