3D Mapped Graph with Gnuplot Not accurate - graph

I am encountering problems while trying to create a 3D (2D mapped) graph.
The data I am generating should create a 3 dimensional normal distribution bump, or, when "mapped", it should look like a flattened 3D graph, with color used as the third dimension
The script I am using to generate the mapped graph is the following:
#!/usr/bin/gnuplot
reset
#set terminal png
set term postscript eps enhanced
set size square
set xlabel "X position"
set ylabel "Y position"
#set zlabel "Synaptic Strength"
#Have a gradient of colors from blue (low) to red (high)
set pm3d map
set palette rgbformulae 22,13,-31
#set xrange [0:110]
#set yrange [0:80]
#set zrange [0:1]
set style line 1 lw 1
#set title "Title"
#Don't want a key
unset key
#set the number of samples
set dgrid3d 51,51
set hidden3d
splot DataFile u 1:2:3
when I run it on the following DataFile (http://www.sendspace.com/file/ppibyw)
I get the following output
The legend indicates a z-range of 0-0.03, however, the datafile has far larger z-values, such as 0.1. Obviously I can't publish a graph that is so inaccurate. Furthermore, I need a better graph in order to gain a better insight as to what is wrong with my simulation.
Does anyone know why gnuplot handles 3d mapped graphs like this? I suspect it has to do with the number, and nature, of the samples.

You problem is in the set dgrid3d 51,51
Have a look at what happens if you write set dgrid3d 51,102 (much better) or set dgrid3d 51,500 (much worse)
The point is that (from the help)
The grid is equally spaced in x
(rows) and in y (columns); the z
values are computed as weighted
averages or spline interpolations of
the scattered points' z values. In
other words, a regularly spaced grid
is created and the a smooth
approximation to the raw data is
evaluated for all grid points. Only
this approximation is plotted, but
not the raw data.
You could try and improve the approximation if you want see the help (?dgrid3d), but I would rather just plot the data straight. You can do this by ditching the dgrid3d command altogether. You will have to modify your data file so that there is a blank line when the x coordinate changes. For example
3.10000000000000142109 4.15692193816530508599 0.00004084299890679580
3.10000000000000142109 4.33012701892219364908 0.00001123746243460237
3.15000000000000124345 0.08660254037844386521 0.00000816290100763514
3.15000000000000124345 0.25980762113533162339 0.00001935936190868058
Then with this simplified script
set terminal png![enter image description here][1]
#set size square
set xlabel "X position"
set ylabel "Y position"
#uncomment the next command to eliminate the mysterious glitch around x=3.4
set yrange [0.1:4.5]
set pm3d map
set output "grid_merged.png"
splot "grid_merged2.dat" u 1:2:3
set output
set term pop
I get
which is better than you get with the interpolated plot. I'm not sure what causes the glitch aroung 3.4, its not there on other (non-mapped) views - altering the yrange eliminates it - although I'm not sure it changing the y-range is cheating in terms of your simulation results....

Related

gnuplot: how to set the size of the points according to the grid

I have the following 'data.dat' file:
# x y z radius
-1.64905083 -1.14142799 -2657.88232 177.358566
-449.735321 416.586914 -2865.25366 10.0000000
178.955292 -256.291138 -2856.96069 89.9588394
-336.942322 184.932343 -2839.22876 90.6131058
-443.635315 -80.0183029 -2863.29077 70.7404404
236.385406 349.893188 -2901.33984 10.0000000
485.313416 -366.513947 -2868.35083 10.0000000
with the positions of the spheres and their radii.
My file.p reads:
set terminal png size 500,500
set output 'file.png'
set multiplot
set xrange [-1000:1000]
set yrange [-1000:1000]
set zrange [-3000:-2500]
splot "data.dat" using 1:2:3:4 ps variable pt 7
splot -(3000**2-x**2-y**2)**(0.5)
but the dots that gnuplot provides me are much bigger.
I understand that it is because ps yields points that are radius times bigger than the normal size.
Meaning that ps does not allow to set the radius of the dots, but rather how many times bigger it is than the normal points.
How can I set the radius of the points please ?
Use "with circles" rather than "with points pt 7".
From the manual:
gnuplot> help with circles
The `circles` style plots a circle with an explicit radius at each data point.
The radius is always interpreted in the units of the plot's horizontal axis
(x or x2). The scale on y and the aspect ratio of the plot are both ignored.
If the radius is not given in a separate column for each point it is taken from
`set style circle`. In this case the radius may use graph or screen coordinates.
Many combinations of per-point and previously set properties are possible.
For 2D plots these include
using x:y
using x:y:radius
using x:y:color
using x:y:radius:color
using x:y:radius:arc_begin:arc_end
using x:y:radius:arc_begin:arc_end:color
By default a full circle will be drawn. It is possible to instead plot arc
segments by specifying a start and end angle (in degrees) in columns 4 and 5.
A per-circle color may be provided in the last column of the using specifier.
In this case the plot command must include a corresponding variable color
term such as `lc variable` or `fillcolor rgb variable`.

gnuplot vector arrow length and streamlines

I have already asked about vector fields in here. Now I want to know a bit more about it.
How can I make it so that each arrow has the same fixed length and define the magnitude of the value by color?
And is it still not possible to plot streamlines in gnuplot? If possible, how can I do that?
For now I have this and need to upgrade it.
set term pngcairo
set title 'Navier-Stokes Equation'
set terminal png size 1280,720
set output 'vec.png'
plot 'vec' u 1:2:($3/$5):($4/$5) w vec t 'Vector Field'
UPDATE
Thanks to #theozh I've got what I wanted. I want to share my result as it could be useful for someone else.
Now I use these instructions to plot my vector field.
reset session
set size square
set palette rgb 33, 15, 10
set term pngcairo
set title 'Navier-Stokes Equation'
set terminal png size 1280, 720
set output 'vec.png'
plot 'vec.dat' u 1:2:(0.08*$3):(0.08*$4):(sqrt($3**2+$4**2)) w vec lw 2 lc palette notitle
About the same length: simply normalize your vectors.
About the color:
you can add a "column" and the end. The last column will define the color according to a palette.
I don't know about streamlines (what exactly they are and how to possibly realize them).
With the example script:
Script: (Edit: define function for length L() to make plot command shorter and clearer.)
### plot with normalized/scaled vectors
reset session
set size square
set samples 25
set palette rgb 33,13,10
set key noautotitle
Scale = 0.5
L(colX,colY) = sqrt(column(colX)**2+column(colY)**2)
plot [-5:5] '++' u 1:2:(Scale*$1/L(1,2)):(Scale*$2/L(1,2)):(L(1,2)) w vec lc palette
### end of script

Plot vertical graphs, gnuplot. Rotate xlabel and key

First of all I would like to apologize for the text, my English is a bit rusty.
So I have a problem plotting a chart and it's been a long time consuming. The chart is below.
This graph is generated from a fit of a normal distribution relative to a data file.
I wanted to plot the gaussians at y, not at x. Make these chart vertical. I researched several things and did not find it. Then I had the idea of ​​rotating it in \TeX, but for that I would have to turn the labels, the tics, and the key.
I use epslatex, so I had issues with transparency. I solved this problem using cairolatex (which generated the figure below). Resolved the transparency, I went to turn all tics and the labels.
First question, how does xlabel spin, I did
set xlabel '$E_p [meV]$' rotate by 180
and it did not work, so my solution was to make a
unset xlabel
set label '$E_p$ [meV]' at 30.5,-550 rotate by 180
and adjust the position, which is nothing practical.
The second question, of which I did not find any solution is, how to turn the key?
Follow the figures for a better understanding ...
Thank you...
You can use set parametric to plot such functions which cannot be written as y(x). In the parametric mode you must specify functions x(t) and y(t) for both coordinates. The range of the dummy variable t is controlled by set trange. A simple example is
set parametric
set trange [-4:4]
set autoscale yfix
y(t) = t
x(t) = t**2
plot x(t), y(t) with lines
Here, the set autoscale yfix automatically adjusts the yrange to the range of y(t), which is desired in this case. The xrange is autoscaled as usual.
So, an extension of the above example for gaussians with some eye candy could be
reset
set samples 1000
set style fill transparent solid 0.50 noborder
set style function filledcurves x1=0
set xlabel "Counts"
set ylabel "Energy"
Gauss(x,mu,sigma) = 1./(sigma*sqrt(2*pi)) * exp( -(x-mu)**2 / (2*sigma**2) )
d1(x) = Gauss(x, 0.5, 0.5)
d2(x) = Gauss(x, 2., 1.)
d3(x) = Gauss(x, -1., 2.)
set encoding utf8
set parametric
set trange [-8:8]
set autoscale yfix
plot d1(t),t title "μ = 0.5 σ = 0.5",\
d2(t),t title "μ = 2.0 σ = 1.0",\
d3(t),t title "μ = -1.0 σ = 2.0"

Gaussian peaks not overlapping in Gnuplot

I’m trying to plot multiple Gaussian functions on the same graph with Gnuplot, which is quite a simple thing. The problem is that the peaks do not overlap and I get the following result that looks like they have different peaks, which they don’t. How can I fix this?
First, it helps to understand how gnuplot generates plots of functions (or really how any computer program must do it). It must convert a continuous function into some kind of discrete representation. The mathematical function to be plotted is evaluated at various points along the independent (x) axis. This creates a set of (x,y) points. A line is then drawn between these points (think "connect the dots"). As you might imagine, the number of discrete samples used affects how accurately the curve is represented, and how smooth it looks.
The problem you have noticed is that the default sample size in gnuplot is a bit too low. The default (I believe) is 100 samples across the visible x-axis. You can adjust the number of samples (to 1000, for example) with
set samples 1000
I have made some example plots of gaussians to illustrate this point. (I made a rough estimate of your gaussian parameters.) Each plot has a different number of samples:
Notice how the lines get too jagged if the sample size is too low. Even the default value of 100 is too low. Setting to 1000 makes it plenty smooth. This is probably more than it needs to be, but it works. If you're using a terminal that generates a bitmap image (e.g. PNG), then you shouldn't need more samples than you have width in pixels used for the x-axis plot area. If you're generating vector based output, then just pick something that "looks right" for whatever you are using it in.
See the question Gnuplot x-axis resolution for more.
By the way, the code to generate the above examples is:
set terminal pngcairo size 640,480 enhanced
# Line styles
set style line 1 lw 2 lc rgb "blue"
set style line 2 lw 2 lc rgb "red"
set style line 3 lw 2 lc rgb "yellow"
# Gaussian function stuff
set yrange [0:1.1]
set xrange [-20:20]
gauss(x,a) = exp(-(x/a)**2)
eqn(a) = sprintf("y = e^{-(x/%d)^2}", a)
# First example (default)
set output "example1.png"
set title "100 samples (default)"
plot gauss(x,8) ls 1 title eqn(8), \
gauss(x,2) ls 2 title eqn(2), \
gauss(x,1) ls 3 title eqn(1)
# Second example (too low)
set output "example2.png"
set title "20 samples (too low)"
set samples 20
replot
# Third example (plenty high)
set output "example3.png"
set title "1000 samples (plenty high)"
set samples 1000
replot

gnuplot: Points overlap in pm3d with a wide xrange

I'm using gnuplot to plot three dimentions of data using pm3d. I'm trying to plot the number of times an event occurs (z value) with respect to the day of the year (x value) and hour of the day (y value).
Using pm3d works great for up to a range of 600 (rought 2 years of data). However, the points begin to overlap each other when a wider range is required.
I believe this is related to the fact that gnuplot isn't stretching the plot to the full size specified in set terminal. I haven't however been able to find a setting that controls this directly.
the script I'm using:
set terminal png size 10000, 1000
set output "%s_plot.png"
set title "%s's"
set ytics 1,1
set xtics 1
set xrange[0:%s]
set yrange[0:23]
set cbrange[0:%s]
set pm3d map
set palette defined (0 "white", 1 "blue", 31 "red")
splot '%s.data'
aspect of the plot for a range of [0:1000] in x:
aspect of the plot for a range of [0,100] in x:
(the images above are just snippets of the whole thing)
What can I do to remedy this? Perhaps the solution is manually setting the points (squares) to have a fixed width.
Thanks.
For the kind of plot that you want, I would replace your last line with:
plot '%s.data' matrix with image

Resources