gnuplot : 3d plot an electromagnetic wave function - gnuplot

Is it possible to do this with gnuplot? Something like on this image (link)
http://i.stack.imgur.com/mZ3M0.gif
I cannot seem to be able to set x = sin(y) and z = sin(y) independently. seeking help!
Thank you!

Yes! You're in luck, I figured this out last week. Here is the gnuplot code I use:
#!/usr/bin/env gnuplot
reset
set term png lw 2
set out 'test.png'
set style data lines
# Set x,y,z ranges
set xr [0:10]
set yr [-2:2]
set zr [-2:2]
# Rotates so that plots have a nice orientation.
# To get parameters, plot in interactive terminal and use 'show view' command.
set view 45,30,1,1
set arrow from 0,0,0 to 10,0,0
unset border
unset tics
splot '+' u 1:(0):(sin($1)) t 'E', \
'+' u 1:(-sin($1)):(0) t 'B'
And here is the figure I get:
I don't have labels, but you can use set label and more arrows to reproduce your example.

You can also define curves like this parametrically:
set parametric
splot u,0,sin(u) title 'E',\
u,-sin(u),0 title 'B'
Note that the u here isn't shorthand for using as you'll often see. u is a dummy variable used in parametric "s"plotting by gnuplot.

Related

Gnuplot use two different scales in the same axis

I am trying to create a graphic using gnuplot 5.0 with two scales in the same x axis. I have managed to create one using the multiplot option with the following code:
reset
set terminal pngcairo
set output "test.png"
unset key
set ylabel "Temperature (C)"
set ytics nomirror
set yrange[0:7]
set multiplot layout 1,2
set xrange [0:5.99] #Avoid plotting the last xtics in the first graphic
set xlabel "Heating time (minutes)"
set rmargin at screen 0.7
plot x
set xrange [0:4]
set xlabel "Seconds after stop"
set rmargin
set lmargin at screen 0.7
set xtics 1
unset ylabel
unset ytics
set y2tics nomirror
set format y2 ''
f(x) = a * exp (-x*b)
a=6
b=1
plot f(x)
With this result:
I want to generate several images like this one and add them in a multiplot arrangement, but I am not sure if using nested multiplots will be easy. Is there an easier way to obtain each of the images without using multiplot, like splitting the xaxis in two components?
Thanks in advance.
Just in case this still might be of interest to the OP or somebody else... You don't explicitly write whether you want to plot functions or data from a datafile. In your examples you use functions.
You can do something without "nested" multiplots, which would certainly be possible as well, but probably getting a bit confusing.
So, maybe the following might be easier. You basically set the xtics "manually". In order to avoid typing the same code several times you can use macros (check help macros).
Code:
### multiplot graph with different x-axis scales
reset session
# define functions
Temperature(x) = x<t0 ? x*a/t0 : a*exp(-(x-t0)*b)
myColor(col) = column(col)<t0 ? 0xff0000 : 0x0000ff
myTic(x,t) = sprintf("%g", x<=t ? x : x-t)
# define macro
myPlot = "\
set xrange[0:t0+t1]; \
set arrow 1 from first t0, graph 0 to first t0, graph 1 nohead; \
set label 1 'heating' center at first t0/2., graph 0 offset 0,-2; \
set label 2 'cooling' center at first (t0+t1/2.), graph 0 offset 0,-2; \
set xtics (); \
do for [i=0:int(t0/dt1)] { set xtics add (myTic(i*dt1,t0) i*dt1) }; \
do for [i=0:int(t1/dt2)] { set xtics add (myTic(i*dt2,t1) i*dt2+t0) }; \
plot '+' u 1:(Temperature($1)):(myColor(1)) w l lc rgb var "
set samples 200
set key noautotitle
set bmargin 3
set ylabel "Temperature"
set grid x,y
set multiplot layout 2,2
t0=6; t1=4; dt1=1; dt2=1; a=6; b=1
#myPlot
t0=4; t1=10; dt1=1; dt2=2; a=4; b=0.5
#myPlot
t0=20; t1=30; dt1=5; dt2=10; a=2; b=0.1
#myPlot
t0=4; t1=4; dt1=1; dt2=1; a=10; b=1
#myPlot
unset multiplot
### end of code
Result:

Gnuplot countours with discrete data points and dgrid3d

I am trying to plot some experimental data points (defined by x, y, and z) and and some "iso-z" lines. To plot contour lines, the data need to be in a grid format. I tried to follow proposed elsewhere, where by means of dgrid3d the experimental, nongrid data, are converted by interpolation into grid points, and use these new data points to draw the contour lines.
The script looks as follows:
reset
set term pdf color enhanced font 'Arial, 18' size 13.5cm,9.2cm
set out 'phasediag.pdf'
#Here I convert the data points, stored in 1f.dat into a grid format.
set table '1f-grid.dat'
set dgrid3d 50,50
splot '1f.dat' u 3:4:2
unset table
#Here I would like to draw the countour lines, to be used after in the plot.
set contour base
set cntrparam level auto 5
unset surface
set table 'cont.dat'
splot '1f-grid.dat'
unset table
# Load the palette color definition.
load 'parula.pal'
set logscale cb
set cbrange[1e5:1e9]
set format cb '10^{%1.1T}'
set cblabel 'Mw / g mol^{-1}' offset 2.5,0
set format x '%1.1f'
set format y '%1.1f'
set label '1{/Symbol F}' at 0.4,6.3
set label '2{/Symbol F}' at 2.15,3
plot[0:2.7][2.5:7] '1f.dat' u 3:4:2 with points pt 5 palette, '2f.dat' u 3:2 with points pt 7 lc rgb "black"
set out
Unfortunately, I get the following error when I try to draw the contour lines in the cont.dat file:
Warning: Cannot contour non grid data. Please use "set dgrid3d".
The error surprises me a bit, as the data produced in the first where produced using dgrid3d and are in grid format.
By commentig out the section in which the contour lines should have been drown, I get the following output:
I would simply draw some lines at constant z-values. Any hint for that?
Thanks in advance,
Leo

GNUPLOT - Add a 2D curve in a 3D Contour plot

I already have a nice 3D plot, with only contour projection from a data file. And I want to add a simple function on it. How can I do this?
here the code:
set autoscale
set terminal png
set contour
set output 'Corrugation_uwtp_HorizontalWind.png'
set pm3d map
set samples 50; set isosamples 50
unset key
set palette rgbformulae 33,13,10
set xlabel "Horizontal distance"
set ylabel "Vertical height"
splot "CORRUGATION_C_UWTP.dat" u 1:2:3
and I want to add following functin:
h(x)=sin(x)
Thank you for your help
Not possible directly, you have to make it in three steps, as 2D plot:
1st plot the contour to a table:
set contour; unset surface
set table $datatable
splot dataf
unset table
2nd plot the contours and your function
plot for [i=0:5] $datatable index i, f(x)
3rd plot the datafile as a coloured surface
replot dataf with image
If you use a gnuplot version prior to 5.0, you have to plot the table output to a temporary file instead of $tablename.

Draw a line in a pm3d map

I have a and I want to overplot on it a .
I define the line as a 3d line with constant height and I thought that with this method I have the possibility to overplot them one to another but, unfortunately, I failed.
I realized in fact that the density map routine in gnuplot take the points of the line too.
This is my script:
reset
#set terminal pngcairo size 800,500 enhanced font 'Verdana,14'
#set output "map.png"
set title 'Map'
m_star=1.054
m_1=0.0093866
m_3=0.0078635
fact1 = (m_star+m_1)**0.5
fact2 = (m_star+m_3)**0.5
set pm3d map interpolate 1,1
set xrange [50.22:52.27]
set yrange [30.29:31.17]
splot "file.txt" u (fact1)*(($1)**(-1.5)):(fact2)*(($2)**(-1.5)):6 notitle ,\
"line.txt" notitle
And here the two files: line and density map.
It is possible to overplot them, in gnuplot?
Thanks a lot for your help !
If you set pm3d, this style is used for all plots unless you explicitely specify a different plotting style. So you must use
splot "file.txt" u (fact1)*(($1)**(-1.5)):(fact2)*(($2)**(-1.5)):6 ,\
"line.txt" with lines
in order to plot line.txt as line:

How to fix GNUPLOT replot issue

I set-up a multiplot like this:
set terminal wxt size 1500,900
set format x "%d%m%y %H:%M:%S"
set xdata time
set timefmt x "%Y%m%dT%H%M%S"
set key font ",6"
set lmargin 10
set rmargin 10
set multiplot layout 2,1
plot "output.txt" u 1:2 w lines axes x1y1, \
"output.txt" u 1:3 w lines axes x1y2
plot "output.txt" u 1:40 w lines axes x1y1, \
"output.txt" u 1:39 w lines axes x1y2
set y2tics border
unset multiplot
Which works, and gives me 2 plots, one above the other.
But pressing the "replot" button (or using zoom) causes the second plot to fill the window - completely hiding the first plot.
Yes, that's how replot behaves. The documentation says: „Note that in multiplot mode, replot can only reproduce the most recent component plot, not the full set.“.
So, what you can do is to put the whole set multiplot ... unset multiplot stuff in an external file, load it, and then load it again. Or put that stuff in a string and eval it several times.
I had the same issue. Solved it with a loop:
set term wxt enh
do for [IDX = 0:1] {
if (IDX==1) {
set terminal png enhanced
set output 'temp.png'
}
set multiplot
set size 1,1
set origin 0,0
plot sin(x)
set size 0.5,0.35
set origin 0.13,0.63
plot cos(x)
unset multiplot
}
set output
set term wxt enh
Here is another workaround. It does not answer the question directly, but it could give idea to other similar issues. Put header, and a footer 'reread', then two context could be choosen for a similar multiplot (done twice)
if (exists("rehearse")) rehearse=1+rehearse; set term x11
if (!exists("rehearse")) rehearse=0; set term png; set output sprintf("test_palette_%s.png", system("date +\"%F\""))
pr "rehearse=".rehearse; show term #<= comment printing
set samples 100; set isosample 100,100
set xrange [0:1]; set yrange [0:1]
set palette defined (0 "white", 1 "red")
set autoscale cbfix; unset colorbox; unset key
set multiplot layout 2,2
plot '++' using 1:2:1 with image
plot '++' using 1:2:2 with image
plot '++' using 1:2:(-$1) with image
plot '++' using 1:2:(-$2) with image
unset multiplot
if(rehearse < 1) reread

Resources