Change location of x-axis in Gnuplot - gnuplot

I'm trying to plot a graph with a set of x-values and y-values in gnuplot. By default. the x-axis is drawn at y=0; I need to change the location of x-axis at y=1 and not at y=0. I was trying options with set xzeroaxis. How do I go about it.

By default, the x-axis is drawn at the bottom border of the graph. xzeroaxis controls only if the x-axis through the origin is drawn or not.
In any case, if you want to have a line at y=1, you can just draw the line there:
gnuplot> set arrow from graph 0, first 1 to graph 1, first 1 nohead
gnuplot> plot x
Tick-marks won't be there, though.
However, if you mean that you want to shift the bottom of the graph to y=1, just use set yrange [1:*].

Related

Modifying the margin alignment in gnuplot in multiplot mode

I have created two plots in multiplot mode using epslatex as output terminal. The y axis labeling is different for both the plots.The first plot's y axis ranges from [0:45] and the second plot's y-axis ranges from [-5e-008 to 4e-007]. Due to the different widths of the y-axis labels, the width of the second plot is less than that of the first plot. I have tried the available scaling options but they do not work. Is it possible to edit the plot so that I can have the same width for both the plots irrespective of the y-axis range?
The problem you're experiencing can be reproduced by doing something like so:
set multiplot layout 2,1
plot sin(x)
plot 100000*sin(x)
The left margins are clearly not aligned. To fix this, you can try an explicit definition of where the margins lie:
set multiplot layout 2,1
set lmargin at screen 0.15
plot sin(x)
plot 100000*sin(x)
If your images are side by side, you can adjust the margins taking the appropriate offset into account:
set multiplot layout 1,2
set lmargin at screen 0.15
plot sin(x)
set lmargin at screen 0.5+0.15
plot 100000*sin(x)

How do you increase the resolution of a contour plot in gnuplot?

I am using an analytical 2D function to make a contour plot. However, I do not get a smooth contour. (For example it should have been a circle but I get a oval shape.)
Here is the code snippet I am using:
splot f(x,y) t ''
set dgrid3d; set view 0,0
set cntrparam levels 10
set contour base
set nosurface
unset ztics
unset zlabel
set border 15
replot
Sounds like a matter of scale of the axes.
You can change the ranges of the axes using the xrange/yrange, etc
See, for example http://gnuplot.sourceforge.net/docs_4.2/node294.html

One big and two small plots in multiplot gnuplot

I am trying to plot three different plots on the same canvas using the multiplot mode of gnuplot (version 5.0.1)
I want an arrangement of these plots in a particular way: final plot should show 2 rows with plot A in the upper row while plots B and C should appear in the lower row side-by-side as if for a lower row we had something like:
"set multiplot layout 1,2"
How can this be achieved?
Thanks in advance
you need to do the multiplot with the most "refined" grid, in this case 2x2 and then specify the size of each plot.
set multiplot layout 2,2
set size 1,0.5 # the first one has to be larger
plot sin(1*x)
set multiplot next # we want to skip the second (upright position)
set size 0.5,0.5 # the second and third have to be 0.5x0.5
plot sin(2*x)
plot sin(3*5)
unset multiplot
or as suggested here https://stackoverflow.com/a/15906085/2743307 it might be simpler to do it upwards (6 lines instead of 8!) but you have to specify the plots in opposite order:
set multiplot layout 2,2 upwards
plot sin(3*x)
plot sin(2*x)
set size 1,0.5
plot sin(1*x)
unset multiplot

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.

Displace z-axis with gnuplot

Is it possible to displace the z-axis to the middle of the x-axis with gnuplot?
I've found a great gnuplot script here which nearly fits my needs perfectly, except that the z-axis should be going up at the middle of the x-axis.
by default gnuplot draws a border and places the labels on this border.
Draw only a border at the bottom, i.e around (x,y)-Plane :
set border 1+2+3+4
or disable it completely:
set border 0
draw a zaxis through the x,y-origin, and place the ztics on the same:
set zzeroaxis lt -1
set ztics axis
same for x and y, if you like.

Resources