adding space between x axis and xtics in gnuplot histogram - gnuplot

Currently I created graphs with small size. The spacing really important at this case. I want to add more vertical space between my xticlabels and x axis.
I have tried to set the x bar with
set xtics offset 0,graph 0.05
my gnuplot output:
The data and gnuplot script still same with my previous question here.

You can do the following:
First add a little bit of bmargin by
set bmargin 3
Since you need to add vertical space between your xticlabels and x-axis, you need to adjust the Y-offset, which can be done by the following
set xtics offset 0,-1,0
You can play around with the values to suite your need.

Related

Set position of one tic number in gnuplot

I'm currently plotting a several plot one side to side. Since there are lots of graphs, I need to waste as little space as possible. At the moment I have this situation:
I want to "right align" the number associated to the first tic in the X axis and "left align" the number associated to the last tic in the X axis. In this way I can achieve the following (saving some pixels):
At the moment both tics and number are set automatically. Is there a way to achieve this in gnuplot? I know you can set via xtics left|center|right the alignment of all the values in the axis.
Regardless of my objective to achieve plot compactness (this may be a XY problem), the question still remains: but does exist a method to manually set the alignment of a particular tic?
Thanks for any kind reply
NOTE: I didn't wrie the version of gnuplot since using a particular version is not a requirement to solve the question.
not very clean solution, but you could for example first define the tics globally and then manually "override" the particular ticks "of interest":
set xr [0:100]
set yr [0:100]
unset key
set xtics 0,20,100
set xtics add (" 0" 0 0)
set xtics add ("100 " 100 0)
plot x w l lc rgb 'dark-red' lw 2
unfortunately, it seems that doing something like this:
set xtics 0,20,100
set xtics add right ("100" 100 0)
affects the alignment of all ticks and not just the added one...
What bugs me in changing the position of only the first and last tic marks is that the space between the labels 20 to 30 won't be the same as 30 to 40 and so on. I've had this problem in the past, and you can play with the number of tics and the range. For example:
set xtics 10
set xrange[15:105]
or if you really want to stick to the 20:100 range:
set xtics 15
set xrange[20:100]
You can also add mxtics to make it look even prettier. This is not a formal solution by any means, just a nice workaround. Hope it helps.

gnuplot multiplot - layout and scale

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?

GNUPlot: Display less marks on x-axis?

I'm trying to get less marks on the x axis to display, since it's not exactly readable as to what size those values are.
Right now I'm using the
set xrange [1000:1000000]
directive.
You can use the command
`set xtics 5e5`
(or some other number) to space the tics further apart. For your data it looks like three tics are fine, you could even get away with two:
`set xtics 1e6`
Sadly gnuplot lacks an option to set the number of tics explicitly.

Creating a microphone polar pattern plot in gnuplot

I would like to create a microphone polar pattern plot that has a scale of -20 (in the center) out to +5 in steps of 5. I have found similar code but nothing that allows for the scales to be negative.
Multiple patterns will then need to added to the plot covering a few different frequencies, I have degree values (0-360) and corresponding dB values (-25 - +5).
This is what the plot should look like (though with slightly different scales):
The closest gnuplot I have found to this is here: How to get a radial(polar) plot using gnu plot?
Perhaps this could be modified to suit my needs?
I would also like 0 degrees to be found at the top of the plot rather than on the right.
I am new to using gnuplot so I am not particularly familiar with its code, therefore it has been difficult for me to modify the code with any great success (so far anyway).
So you want to plot a polar function, e.g. r(theta) = 1 + sin(theta).
Plotting the function is quite easy, just do
set polar
plot 1+sin(t)
A simple polar grid can be plotted with
set grid polar
but that has the raxis and the rtics on a different position than where you wanted. It is not problem to specify custom labels. But angular labels aren't supported, so you need to set them manually. And the border and the other axes and tics must be unset.
To get the very same image as you showed, use the following script:
set terminal pngcairo size 700,600 font ',10'
set output 'cardioid.png'
set angle degree
set polar
set size ratio 1
set tmargin 3
set bmargin 3
set style line 11 lc rgb 'gray80' lt -1
set grid polar ls 11
unset border
unset xtics
unset ytics
r=1
set rrange [0:r]
set rtics 0.166 format '' scale 0
set label '0°' center at first 0, first r*1.05
set label '180°' center at first 0, first -r*1.05
set label '90°' right at first -r*1.05, 0
set label '270°' left at first r*1.05, 0
set for [i=1:5] label at first r*0.02, first r*((i/6.0) + 0.03) sprintf("%d dB", -30+(i*5))
unset raxis
plot 0.5*(1+sin(t)) linewidth 2 t ''
With the result:
That includes some offsets for the labels, which depend on the terminal, the canvas size and the font size. So you may need to adapt them.
I had to increase the top and bottom margins a bit (here by 3 character heights) in order to have enough space for the angular labels. They aren't included in the automatic margin calculations, because the don't belong to an axis.
Unfortunately Christoph's answer is wrong.
You can see that if you check where the plot curve crosses the 5db circle.
What should be plotted is
20*log10(A+B*cos(t))
where A+B = 1 and A - B determines the (nominal) directivity pattern.
The first diagram seems to be for A=B=0.5 which makes for a cardioid pattern.

Gnuplot: automatic placing of x2 tic labels

I've got data that I want to plot in gnuplot that looks something like this:
1.08 1 4.8
1.53 2 5.9
2.11 3 5.1
2.60 4 6.0
Not that it's terribly important, the first column is the running time of a genetic algorithm, the second column is the generation number, and the third is average fitness.
If I plot it using plot datafile.dat using 1:3 with lines it looks fine, with tics appropriately spaced. However, while I want the x-tics to be labelled with the time, I want the x2-tics to be labelled with the generation number. This is easy to do with plot datafile.dat using 1:3:x2ticlabels(2) with lines, but for the x2-axis it adds a tick for every single line in the data file, instead of automatically choosing an appropriate number of tics.
My full data file has thousands of entries, which results in a solid black line at the top of the graph where the tics would be spaced, and a larger solid black line above where the labels would be placed. Even if I try to manually tell gnuplot how often to place tics on the graph using set x2tics 100 it still displays them for every entry. Is there a way to fix this? Obviously I'd prefer which tics are shown to be automatically chosen, but if I have to do it manually that's fine. The full gnuplot config file is pretty basic, just:
set logscale y 10
set x2tics
plot datafile.dat using 1:3:x2ticlabels(2) with lines
Here's a solution that will only put a label for every other line in the datafile.
plot 'test.dat' u 1:3:x2ticlabels(int($0)%2==0?stringcolumn(2):'')
One thing that is a little interesting is that the tics don't quite line up with the points. I haven't figured out why yet. With thousands of points, you're probably not likely to notice, but with your example datafile with 4 points, it's noticeable.
Unfortunately, it still draws a tic on the axis for every line in the datafile. set x2tics scale 0 will make those tics go away completely.

Resources