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)
Related
I know that gnuplot has the great type of plot that is filledcurve, which you can make a filled region between two curves that are presented like 1:2:3, it will make a curve between columns $2 and $3 for the same x value $1. But how can I fill this region in the graph below in gnuplot? The range is in x direction like x1:x2:y, same value of y.
My data it's in form like:
# rho1 rho2 C
0.8022651311239721 0.8299444680667378 0.00005011872336272725
0.8022624676512962 0.8299464715046031 0.00004466835921509635
0.8022618998639025 0.8299490455369624 0.000039810717055349695
0.8022533810411624 0.8299390462160209 0.000035481338923357534
...
But I can separate that in two archives too.
Here is a useful trick that uses the 3D plotting style with zerror and then sets the view angle so that it looks like a 2D x/y plot. I don't have enough of your data to replicate the plot you show so I use a junk data file just for the purpose of showing how the plot works:
# 3D plot style "with zerror" takes 5 columns of input
# x y z zlow zhigh
# We will choose a view angle such that "z/zlow/zhigh" is the horizontal axis
# "x" is the vertical axis
# "y" is unused because it is along the line of sight
# For your data as described
rho1 = 1 # column 1
rho2 = 2 # column 2
c = 3 # nominal y value, we use it for X
junk = 0 # unused constant coordinate
rhomean(c) = (column(rho1) + column(rho2)) / 2.
set view 270, 0
set view azimuth -90
unset ytics
set zlabel "ρ" # horizontal axis in this projection
set xlabel "C" # vertical axis in this projection
set zrange [0:50] # Note how this affects the horizontal axis!
splot "data" using c:(junk):(rhomean(c)):rho1:rho2 with zerror lt black fc "gold"
The with zerror plot style and the set view azimuth command both require a reasonbly current version of 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.
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:
I'm plotting six differents graphs in a multiplot. I would like to autoscale axis. Values that are plotted are readed from txt files that are different in each execution, so I can't fix any value in xrange and yrange. That's why I need to autoscaling axis.
The problem is that multiplot doesn't allow to change term, so I can't plot in a dummy terminal and I don't know GPVAL_Y_MIN and GPVAL_Y_MAX values.
Any ideas? If graphs in multiplot don't have correct scale it is not very useful to display my data.
You can use
set autoscale yfix
to have an autoscaled y-range but without extending it to the next tics. This would give you different ranges for each subplot.
If you need one yrange for all subplots, you can use the stats command (requires version 4.6). Using GPVAL_Y_* after plotting to a dummy terminal was the way to go for gnuplot versions prior to 4.6 (more a workaround).
Then you can iterate over all files to determine the common yrange:
filelist="A.txt B.txt C.txt D.txt E.txt F.txt"
i = 0
do for [f in filelist] {
stats f using 1:2 nooutput
if (i == 0) {
min_y = STATS_min_y
max_y = STATS_max_y
i = 1
} else {
min_y = (STATS_min_y < min_y ? STATS_min_y : min_y)
max_y = (STATS_max_y > max_y ? STATS_max_y : max_y)
}
}
set yrange [min_y:max_y]
set multiplot
...
The nature of my plot is such that absolute labels don't really work; I can't restrict the range in y, so wondered if there was a way to either include my label text inside the key or have it placed relative to the key (i.e. below)
set term png enhanced size 1024,768
set title "{/=15 1D My title}\n - by me"
set xlabel "x"
set ylabel "y"
set label "V_0 = 10\n E = 1" #this is the bit I want to reposition
set out 'trial.png'
set xrange [-2.5:2.5]
set arrow from -2,-2000 to -2,2000 nohead size screen 0.025,30,45 ls 1
set arrow from 2,-2000 to 2,2000 nohead size screen 0.025,30,45 ls 1
plot 'data.dat'
PS: also, is there a better way to get my vertical lines at x = -2 and x = 2? The arrows solution is again not ideal since my y range is often greater or smaller than 2000.
In gnuplot you can use different coordinate systems to set arrows, labels, key and objects. The coordinates may be specified as
first: value on the left and bottom axes.
second: value on the right and top axes.
graph: relative to the area within the axes, 0,0 is bottom left and 1,1 is top right.
screen: relative to the entire canvas.
character: depends on the chosen font size.
With this, you can set your arrows in the following way:
set arrow from first -2,graph 0 to first -2,graph 1 nohead ls 1
set arrow from first 2,graph 0 to first 2,graph 1 nohead ls 1
You don't need to set a size if you don't have an arrow head.
Although I did not fully understand your label question, I'm sure you will solve it with these information about different coordinate types:
set label "V_0 = 10\n E = 1" right at graph 0.9, graph 0.8