I want to plot a parallel plate capacitor setup with plates at x = -1 and x = +1 lying in the yz plane. I have to then show the potential varying in between them and the vector plot of electric field.
How can I generate the solid plates in 3D?
I am not sure if Gnuplot is the best tool for this, nevertheless an approximation could be perhaps achieved with parametric plotting, where the x-coordinate is fixed and y/z are directly mapped to the u/v parameters:
set terminal pngcairo rounded font ",16"
set xr [-4:4]
set yr [-4:4]
set zr [-4:4]
set palette defined ( 0 "black", 1 "#666666" )
set pm3d at s
unset surface
unset colorbox
set isosamples 100
unset key
set parametric
set ur [-2:2]
set vr [-2:2]
splot \
-1,u,v w l lc rgb '#333333', \
+1,u,v w l lc rgb '#333333'
#or set larger ur/vr and use, e.g.,
# -1,(u>-2&&u<2?u:1/0),(v>-2&&v<2?v:1/0) w l lc rgb '#333333', \
# +1,(u>-2&&u<2?u:1/0),(v>-2&&v<2?v:1/0) w l lc rgb '#333333'
This would give you:
Related
I would like to plot a function f: R -> R^2 like f(t) = (cos(t), sin(t)), but I don't see how to do it.
f(t) = (cos(t), sin(t))
plot f(x) # doesn't work
splot f(x) # doesn't work either and is probably not what I want
Is there a way to plot such a function in gnuplot?
Please check help parametric, help special-filenames, help sampling and this: http://gnuplot.sourceforge.net/demo_5.4/param.html.
Here are two approaches:
Script:
### parametric curves
reset session
fx(t) = cos(t)
fy(t) = sin(t)
set size ratio -1
set xrange[-1.1:1.1]
set yrange[-1.1:1.1]
set multiplot layout 1,2
set parametric
plot [t=0:2*pi] fx(t), fy(t) w l lc "red"
unset parametric
plot sample [t=0:2*pi] '+' u (fx(t)):(fy(t)) w l lc "blue"
unset multiplot
### end of script
Result:
This was created with Matplotlib. Is it possible to make the same type of shading in Gnuplot 5?
I'm not aware that gnuplot has a gradient fill option, but I could be wrong.
The following is a bit of an "ugly" workaround. You basically create 3 plots on top of each other. You might want to adjust the palette to get the desired colors and a smooth transition.
a dummy plot to get the palette as background (i.e. the colorbox as large as the graph)
cover the part above y>f(x) and y>0 to x2-axis as well as below y<f(x) and y<0 to x1-axis.
plot again f(x) to see f(x) and the axes tics again
Edit:
The earlier version of the code used multiplot. It's not necessary, just use set colorbox back. But then set xzeroaxis ls -1 is not visible anymore, add plot 0 w l ls -1 instead.
Code:
### filled curve with gradient
reset session
f(x) = sin(x)/(1+x)
fabove(x) = f(x)<0 ? 0 : f(x)
fbelow(x) = f(x)>0 ? 0 : f(x)
set samples 200
set palette defined (0 "white", 1 "red", 2 "black")
set colorbox back user origin graph 0, graph 0 size graph 1, graph 1
unset cbtics
set xrange[0:15]
set xzeroaxis ls -1
set yrange[-0.2:0.5]
plot fabove(x) w filledcurves x2 fc rgb "white" not, \
fbelow(x) w filledcurves x1 fc rgb "white" not, \
f(x) w l lw 2 lc rgb "black", \
NaN palette, \
0 w l ls -1
### end of code
Result:
I am plotting a simple 3D surface in GNUPlot for the following function:
f(x,y)=x**2-y**2
This works fine. However I would like to only display the outline of the surface. Without the colors or grid lines along it. Is there a way to achieve this?
Here is an example of what I am looking to create:
Outline of the surface
Thank you for your help.
In this specific case you could also adjust the number of isolines drawn by gnuplot:
f(x,y) = x**2 - y**2
set xr [-10:10]
set yr [-10:10]
unset key
set isosamples 2,3
splot f(x,y)
I'm not aware of a general solution. In your special case I would consider just drawing each single line using parametric mode like in this script:
f(x,y) = x**2 - y**2
set parametric
set urange [-10:10]
set vrange [-10:10]
set nokey
#set border 0 # uncomment to remove the axes
#unset xtics
#unset ytics
#unset ztics
set arrow 1 from 0,0,0 to 0,0,100
set arrow 1 head lw 2
splot u,-10,f( u,-10) lc 0, \
u, 10,f( u, 10) lc 0, \
-10, v,f(-10, v) lc 0, \
10, v,f( 10, v) lc 0, \
u, 0,f( u, 0) lc 0
This is the result:
I basically want to draw 2d color surface (or contour plot)
of rosenbrock function f(x,y) = (a-x)^2 + b * (y-x*x) ^2
and append some points (x,y) on this image.
Sample file with points looks as follows:
#x #y
15.00000 12.00000
8.00000 9.00000
The thing is, both graphs do not share the same coordinate system on output image:
coordinate systems do not overlap on each other
gnuplot code:
#!/usr/bin/env gnuplot
reset
set terminal png size 700,700
enhanced set output 'output.png'
set tmargin screen 1
set bmargin screen 0
set border 0 back
set size square
xr=20
yr=20
set xrange [-xr:xr]
set yrange [-yr:yr]
unset key #disablegraph name
unset colorbox
set surface
set multiplot
set view map
set cntrparam levels 10# contour tenderness
set style data pm3d
set pm3d
set contour
a=1 #rosenbrock parameter
b=1 #rosenbrock parameter
#set isosamples 50
splot (a-x) * (a-x) + b * (y-x*x) * (y-x*x) # 2d rosenbrock
unset view
unset pm3d
plot 'data.dat' pt 5, 'data.dat' using 1:2:($0+1) with labels offset 1 notitle
mixing 2d and surface plots with multiplot is usually a mess. I guess you probably don't need multiplot in this simple case. Maybe something like this is enough:
set size square
xr=20
yr=20
set xrange [-xr:xr]
set yrange [-yr:yr]
unset key
unset colorbox
set surface
set pm3d map
set contour
set cntrparam levels 10# contour tenderness
rosenbrock(x,y,a,b)= (a-x) * (a-x) + b * (y-x*x) * (y-x*x)
splot rosenbrock(x,y,1,1) w pm3d, 'data.dat' u 1:2:0 w p pt 5, 'data.dat' using 1:2:(1):($0+1) with labels offset 1,1 notitle
I have the following script to plot histograms:
set terminal postscript eps enhanced color
set title "Histogram\_CreatesFile"
colour1="#00A0ff"
colour2="navy"
colour3="#ffA000"
colour4="#800000"
set output 'Histogram_CreatesFile.eps'
set yrange [0:]
set style fill solid 0.8 border -1
bin_width = 0.2
set boxwidth bin_width
bin_number(x) = floor(x/bin_width)
rounded(x) = bin_width * ( bin_number(x) + 0.5 )
plot 'Histogram_CreatesFile.txt' using (rounded($1)):(1) smooth frequency with boxes lc rgb colour1 notitle
This is supposed to be empirical realisation of some distribution, so to make it more clear I would like to:
Normalize the bars appropriately so that they can be compared to a density function (I guess the sum of the areas of the bars should sum-up to unity? That would mean that the height of each bar should be divided by barWidth*numberOfElements)
On the same picture plot the theoretical distribution function, given by a closed form formula (e.g. Gaussian)
How can I achieve this?
I managed to solve this issue.
(1) The normalization goes into the column after the colon, so the plot command becomes:
plot 'ConfUoMBM1validation0_0.txt' using (rounded($1)):(1/(bin_width*STATS_records)) smooth frequency with boxes lc rgb colour1 notitle
(2) Plotting of functions can't be easier, just do it after a coma as you would normally do
So the final outcome is:
set terminal postscript eps enhanced color
set title "ConfUoMBM1validation0 0"
colour1="#00A0ff"
colour2="navy"
colour3="#ffA000"
colour4="#800000"
set output 'ConfUoMBM1validation0_0.eps'
set style fill solid 0.8 border -1
bin_width = 0.926911
set boxwidth bin_width
bin_number(x) = floor(x/bin_width)
rounded(x) = bin_width * ( bin_number(x) + 0.5 )
invsqrt2pi = 0.398942280401433
normal(x,mu,sigma)=sigma<=0?1/0:invsqrt2pi/sigma*exp(-0.5*((x-mu)/sigma)**2)
stats 'ConfUoMBM1validation0_0.txt' using (rounded($1)) nooutput
set xrange [STATS_min-bin_width/2.:STATS_max+bin_width/2.]
set yrange [0:]
plot 'ConfUoMBM1validation0_0.txt' using (rounded($1)):(1/(bin_width*STATS_records)) smooth frequency with boxes lc rgb colour1 notitle, normal(x,-0.14166974006432781,4.6345562297659741) with lines lc rgb colour2 lw 5 notitle