gnuplot ytics notation like Matlab - gnuplot

I want set the ytics notation like this Matlab figure (with only one x10^-5 on the graphics box) whit gnuplot. Is it possible?

You can certainly do this by hand in gnuplot, using the enhanced option of many terminals and setting a label:
set terminal pngcairo enhanced
set output "out.png"
set tmargin at screen 0.95
set label at graph 0,1.05 left 'x 10^{-5}'
plot x
But note that you'll have to scale the y axis also by hand, for instance by scaling the output of a function f(x) to 1e5 * f(x) in the present case.
If you use the latex terminals then simply use latex syntax for the label: set label ... '$\times 10^{-5}$'.
If this is not enough for you, then maybe someone else might come with a more automatic solution.

A more automated solution is to use the unknown terminal to estimate the autoscaled yrange limits, calculate the order of magnitude, set the scale and replot:
set terminal push
set terminal unknown
scale = 1.0
plot 'data.dat' using 1:($2/scale) w lp
set terminal pop
max(x,y) = (x > y ? x : y)
exponent = log10(max(abs(GPVAL_Y_MAX), abs(GPVAL_Y_MIN)))
oom = (ceil(exponent) == exponent ? exponent : ceil(exponent) - 1)
scale = 10**oom
set encoding utf8
set label left at graph 0, graph 1.05 sprintf('✕ 10^{%d}', int(oom)) enhanced
set tmargin 4
replot

Related

How to make dashed grid lines intersect making crosshairs in gnuplot?

I'm plotting some data and I want to use dashed grid lines.
Any dashed grid line would suffice, but I prefer a "long dash, short dash, long dash" format.
For example, given the following code
set grid lc rgb "#000000" lt 1 dt (50, 25, 20, 25)
plot x**2
I get this result
But I would rather the grid lines intersection to happen always at the middle of two dashes, like this
If I could make horizontal grid lines different to vertical grid lines and I could add some offset to each one, then I'd imagine there's a way to accomplish this. But I can't seem to do that either.
It looks like gnuplot cannot have two different dashstyles for x-grid and y-grid.
One workaround I see currently is to plot two identical plot on top of each other. One with appropriate x-grid lines and the other with appropriate y-grid lines.
If you want a dash pattern with proportions of (50-25-20-25), this correspond to (25-25-20-25-25-0) or (5-5-4-5-5-0) between two tics.
Furthermore, the dash and gap length numbers, e.g. in dt (50,25,20,25), seem to be in a fixed relation to the graph size. The "empirical" factor is 11 with good approximation (at least for the wxt terminal which I tested under gnuplot 5.2.6).
Edit: actually, the code below gives different results with a qt terminal. And it's not just a different factor. It's more complicated and probably difficult to solve without insight into the source code. So, the fact that the following seems to work with wxt terminal (maybe even just under Windows?) was probably a lucky strike.
With this you can create your dash lines automatically resulting in crosshairs at the intersections of the major grid lines.
Assumptions are:
your first and last tics are on the borders
you know the number of x- and y-intervals
You also need to know the graph size. These values are stored in the variables GPVAL_TERM..., but only after plotting. That's why you have to replot to get the correct values.
This workaround at least should give always crosshairs at the intersection of the major grid lines.
Edit 2: just for "completeness". The factors to get the same (or similar) looking custom dashed pattern on different terminals varies considerably. wxt approx. 11, qt approx. 5.6, pngcairoapprox. 0.25. This is not what I would expect. Furthermore, it looks like the factors slightly depend on x and y as well as graph size. In order to get "exact" crosshairs you might have to tweak these numbers a little further.
Code:
### dashed grid lines with crosshairs at intersections
reset session
TERM = "wxt" # choose terminal
if (TERM eq "wxt") {
set term wxt size 800,600
FactorX = 11. # wxt
FactorY = 11. # wxt
}
if (TERM eq "qt") {
set term qt size 800,600
FactorX = 5.58 # qt
FactorY = 5.575 # qt
}
if (TERM eq "pngcairo") {
set term pngcairo size 800,600
set output "tbDashTest.png"
FactorX = 0.249 # pngcairo
FactorY = 0.251 # pngcairo
}
set multiplot
set ticscale 0,0
Units = 24 # pattern (5,5,4,5,5,0) are 24 units
# set interval and repetition parameters
IntervalsY = 10
RepetitionsY = 1
IntervalsX = 4
RepetitionsX = 3
# initial plot to get graph size
plot x**2
gX = real(GPVAL_TERM_YMAX-GPVAL_TERM_YMIN)/IntervalsY/Units/FactorY/RepetitionsY
gY = real(GPVAL_TERM_XMAX-GPVAL_TERM_XMIN)/IntervalsX/Units/FactorX/RepetitionsX
# first plot with x-grid lines
set grid xtics lt 1 lc rgb "black" dt (gX*5,gX*5,gX*4,gX*5,gX*5,0)
replot
unset grid
# second plot with y-grid lines
set grid ytics lt 1 lc rgb "black" dt (gY*5,gY*5,gY*4,gY*5,gY*5,0)
replot
unset multiplot
set output
### end of code
Result:
Not really. The closest I can think of is
set grid x y mx my
set grid lt -1 lc "black" lw 1 , lt -1 lc bgnd lw 16
set ticscale 1.0, 0.01
set mxtics 4
plot x**2 lw 2
But that leaves the vertical grid lines solid.

How to make the same scale of x and y in gnuplot without full autoscaling?

I know that "set view equal xy" automatically sets the same scales for x and y, but it is not exactly what I want. I expect that I define 'xrange [a:b]' and 'yrange [c:?]' and the last number '?' would be defined automatically from the knowledge of 'set view equal xy' and from the knowledge of the lengths of the axes.
I can try to explain in other words. I write the following:
reset
set xrange [-5:5]
set yrange [-1:?]
set view equal xy
plot sin(x) with lines
The resulting scaling depends on the plotted function and gnuplot does not follow the entered values. But it should be possible to calculate '?' just from the knowledge of the visible lengths of axes (Lx,Ly) and condition of 'equal scales' (Sx=Sy):
Sx = Sy
Lx/(-5-5) = Ly/(-1-?)
? = - Ly/Lx * (-5-5) -1
This is what I expect from gnuplot when asking for equal scales. Could anyone help me to achieve this 'not fully auto'-scaling?
Thanks in advance.
I'm not fully sure what you want, but using set yrange [-1:*] should work fine. That autoscales only the upper y-value:
set xrange [-5:5]
set yrange [-1:*]
set size ratio -1
plot 2*x, 0.2*x
The output with 4.6.5 is:

wxMaxima + gnuplot = Mathematica-like densitymap with a twist

I would like to plot the frequency-domain response of a filter in a similar manner to how the pole-zero plots are on the Wikipedia's "Chebyshev filter" page: http://en.wikipedia.org/wiki/File:Chebyshev_Type_I_Filter_s-Plane_Response_(8th_Order).svg . In particular, what I would like is to cut the plot in half along the Y axis and to make the cut stand out as representing the frequency response.
So far I have managed to get this:
The maked seam can be seen but it doesn't stand out, as if freshly welded. I hope the meaning gets to you because I can't find a better explanation now.
Now, what I have, so far, with wxMaxima's draw3d() function, is this:
draw3d(logx=false,logy=false,logz=true,
enhanced3d=false,line_width=2,color=red,explicit(cabs(Hs(x+%i*y)),x,-0.01,0,y,-3,3),
enhanced3d=[z**.5,x,y,z],palette=gray,proportional_axes=xy,
/* cbrange=[0.05,100.95], */ view=[0,0],yv_grid=101,xu_grid=101,
explicit(cabs(Hs(x+%i*y)),x,-1,0,y,-3,3))$
where Hs(s) is defined earlier, say:
Hs(s):=0.0248655/((s+0.210329)*(s^2+0.12999*s+0.521695)*(s^2+0.340319*s+0.22661))$
I don't know how to make the frequency response stand out, the order of printing doesn't seem to matter. Does anyone know if it can be done and, if so, how?
I don't know how to achieve that with maxima, but here is a solution with gnuplot only. This uses the + pseudo filename to create the 1D-plot for x=0 with splot. Complex numbers are specified with brackets, {x,y}, i.e. i = {0,1}:
set terminal pngcairo size 1000,800
set output 'chebyshev.png'
N = 501
set isosamples N
set samples N
set pm3d interpolate 3,3
set palette gray
set cbrange [*:10]
set xrange [-1:0]
set yrange [-3:3]
set logscale z
set autoscale zfix
set view 120,278
unset key
set grid
Hs(s) = 0.0248655/((s+0.210329)*(s**2+0.12999*s+0.521695)*(s**2+0.340319*s+0.22661))
splot abs(Hs(x+{0,1}*y)) w pm3d, \
'+' using (y = ($0/(N-1.0) * 6 - 3), 0):(y):(abs(Hs({0,1}*y))) w l lw 3
The result with 4.6.3 is:

Gnuplot issue? Contours connecting in a strange way

I'm quite new to gnuplot and I'm using this code;
set xlabel 'x';
set ylabel 'y';
set palette rgbformulae 7,5,15;
set surface;
set cntrparam levels 10;
set isosamples 50;
unset key;
set title 'Magnetic Field Component, By';
splot 'ByF.txt' w l palette title 'By';
My issue is it comes out looking like this;
It looks strange because it's adding contours or lines from y = 0 to y = 2 at z = 0 for all values of x. How do I stop it doing this? I have another plot using a different .txt file, inside these text files is basically this graph but rotated 90 degrees in the x-y plane which DOESN'T give me this weird z = 0 plane of lines. So it must be some setting of the contours which is going wrong.
This is probably due to the fact that the data-file should leave one blank line between each x (or y) scan (called block in gnuplot)

Fit exception on gnuplot

I try to plot a data with an exponentiel regression :
set terminal postscript enhanced color
set output 'fichier.ps'
set logscale y
set logscale x
set format y "10^{%L}"
set format x "10^{%L}"
set key inside right top
set xlabel " lines "
set ylabel " Time(nanoseconds)"
f(x) = a + b*exp (x)
fit f(x) 'fichier.csv' using 16:17 via a, b
plot 'fichier.csv' using 16:17 with points title "title" lw 3 pt 4 linecolor rgb "#FF0000", f(x) with lines title "regtitle" linecolor rgb "#000000" lw 3
I have this error :
Max. number of data points scaled up to: 3072
Undefined value during function evaluation
and i run on gnuplot 4.4
how to resolve problem ?
The message Max. number of data points scaled up to: 3072 has nothing to do with the fit error, see also Gnuplot : How to set max number of data points for fit
Your fit error likely is due to faulty data or badly set initial values of the parameters. If you don't set the variables at all before the fit, gnuplot initialises them with 1.0, which might be totally off. Exponential fits are notoriously unstable with bad starting values. You might use gnuplots stats command to find out a bit more about your data before fitting.

Resources