wxMaxima + gnuplot = Mathematica-like densitymap with a twist - gnuplot

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:

Related

gnuplot badly renders heat map on uneven grid

I am trying to plot a heat map of 3D results, a f(x,y) function, obtained on an uneven grid.
The plot I obtain gives me some ugly empty spaces at the top of the graph.
Below are minimal scripts to reproduce the issue I am facing.
#Generate some dummy data
f(x,y) = sqrt(x**2 + y**2)
set table
set samples 1000
set output "table.dat"
splot [0:10][0:10] f(x,y)
The plotting script :
# plot it
set term x11
set out
set pm3d map
splot [1:5] [0:2] "table.dat" u ($1):($2/$1):($3)
Since the y-axis value depends on the x-axis, the grid is now even. As can be seen in the following figure gnuplot fails to fill-up some space close to the top border of the plot. Changing the axis limits doesn't help.
sample impage plot
Any idea how to fill-up the white triangles and make this plot look nicer ?
Thanks for your help.
You can use dgrid3d for 2-d interpolation. With your using specification ($1):($2/$1):($3) the domain where you have data points is very irregular. It helps to tell dgrid3d that you are interested only in a small rectangle by setting all other values to NaN. For example:
set pm3d map
set dgrid3d 100,100 qnorm 4
splot [1:5] [0:2] "table.dat" u ($1 >= 1 && $1 <= 5 ? $1 : 1/0):($2/$1 > 0 && $2/$1 < 2 ? $2/$1 : 1/0):3
You will have to experiment with the various options of dgrid3d to get a reasonable interpolation.

gnuplot ytics notation like Matlab

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

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:

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)

GnuPlot not plotting over the whole range

Basicaly, I have the following code:
binom(n,k) = n!/(k!*(n-k)!)
hyperge(N,K,n,k) = binom(K,k)*binom(N-K,n-k)/binom(N,n)
hypergge(N,K,n,k) = sum [i=k:K] hyperge(N,K,n,i)
set term png
set output "onedrop.png"
set xlabel "Decksize"
set ylabel "Chance of having one of four one-drops on turn 1"
plot [x=59:209] (hypergge(floor(x)-9,4,6,1) + (1-hypergge(floor(x)-9,4,6,1))*(hypergge(floor(x)-9,4,6,1)))*100 with lines notitle lw 2
(The only thing that might be really important about hypergge is that it use factorials, i.e. needs integers as arguments).
which produces the following output
So for some reason, gnuplot just stops drawing the plot at ~180, and I see absolutely no reason why it behaves like that...
170! is the last factorial which gnuplot can evaluate:
gnuplot> print 170!
7.257415615308e+306
gnuplot> print 171!
inf.0

Resources