Space in legend between symbol and text in gnuplot - gnuplot

Dear Experts of gnuplot,
I want to change the spacing between key text and key symbol.
Please help me with this. What command should I use for the purpose?
Thanks in advance.

The space between symbol and key entry is so large because it is reserved for line plots:
plot sin(x) with points, cos(x) with lines
If you mix these two styles in one figure, you will want to keep the horizontal spacing. However, if you are sure that you will use only points, then the horizontal space might indeed seem too large. The samplen option of set key can be used for that purpose, it can even be set to negative: set key samplen -1 (default is 4)

Related

Gnuplot: align key directly under xlabel?

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

gnuplot - distance between columns in a key [duplicate]

Please have a look at the attached plot created from Gnuplot. I am facing two issues with it.
1) The empty white space in the left side of the key box (legend box). Is there any way to remove that extra empty white space? Neither I want to lose the key box nor compromise on the Greek letters used. Also, note that final output format has to be eps.
2) There is also too much space between the y-axis and the y-label. How to optimize it?
Please help.
Gnuplot_Image
Gnuplot doesn't know the exact width and height of the ultimately formatted strings. It rather tries to approximate the width based on some font information. That does also happen when using e.g. the qt terminal with a title containing only very narrow letters:
set terminal qt
set key box
plot x title 'iiiiiiiiiii'
That becomes even more complictated when TeX strings are involved. Use the width parameter for set key with a narrow value to decrease the key's width. You must manually estimate the actual value to use:
set terminal qt
set key box width -6
plot x title 'iiiiiiiiiii'
The same argumentation applies to the positioning of xlabel and ylabel. Here, you must use the offset parameter to correct the position:
set xlabel 'xlabel' offset 0, -0.5
set ylabel 'ylabel' offset 0.5, 0

In gnuplot, how do I place the key some distance from the border?

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

Gnuplot: Unwanted white space on the left side in legend key box

Please have a look at the attached plot created from Gnuplot. I am facing two issues with it.
1) The empty white space in the left side of the key box (legend box). Is there any way to remove that extra empty white space? Neither I want to lose the key box nor compromise on the Greek letters used. Also, note that final output format has to be eps.
2) There is also too much space between the y-axis and the y-label. How to optimize it?
Please help.
Gnuplot_Image
Gnuplot doesn't know the exact width and height of the ultimately formatted strings. It rather tries to approximate the width based on some font information. That does also happen when using e.g. the qt terminal with a title containing only very narrow letters:
set terminal qt
set key box
plot x title 'iiiiiiiiiii'
That becomes even more complictated when TeX strings are involved. Use the width parameter for set key with a narrow value to decrease the key's width. You must manually estimate the actual value to use:
set terminal qt
set key box width -6
plot x title 'iiiiiiiiiii'
The same argumentation applies to the positioning of xlabel and ylabel. Here, you must use the offset parameter to correct the position:
set xlabel 'xlabel' offset 0, -0.5
set ylabel 'ylabel' offset 0.5, 0

gnuplot: legend gets hidden behind data

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.

Resources