I'm trying to plot the following 3 intersecting planes:
x + 2y + 4z = 7
2x + 3y + 3z = 1
3x + 7y + 2z = -11
To add emphasis, I wanted to include some headless arrows along the intersection of each pair of planes and a small sphere to indicate the intersection point. But for some reason the planes themselves seem to be out of alignment with the axes. From the equations I can easily find the coordinate of the intersection point, find the coordinates of the edges of the lines that run along the intersection of each pair of planes and if needed find the parametric equation of the lines. But so far when I plot the lines as arrows from the edges of my plot or the intersection as a circle, the planes seem to be wrongly positioned within the coordinates. I can see that the circle or the lines are positioned correctly, but the planes themselves seem to have been shifted. What could be causing this? Am I entering the equations wrong? Maybe the shift of the xy plane moves things around? I think it must be something obvious I'm just not seeing. I find it quite puzzling.
reset
samps = 500
set samples samps,samps
set isosamples samps,samps
f(x,y) = 7/4 - x/4 - y/2
set table $Data01
splot f(x,y)
unset table
g(x,y) = 1/3 - 2/3*x - y
set table $Data02
splot g(x,y)
unset table
h(x,y) = -11/2 - 3/2*x - 7/2*y
set table $Data03
splot h(x,y)
unset table
Zmin = 1.0
Zmax = 3.5
set xrange [-1.2:0.5]
set yrange [-4:0]
set zrange [Zmin:Zmax]
set hidden3d
set xlabel 'x'
set ylabel 'y'
set zlabel 'z'
set xyplane at Zmin
unset xzeroaxis
unset yzeroaxis
unset zzeroaxis
set border 1023-128
set xtics out nomirror
set ytics out nomirror
set ztics out
#set xtics add ('' -4)
Frac(z) = (z - Zmin) / (Zmax - Zmin)
#MyPalette01
Red01(z) = 0
Green01(z) = 255*256
Blue01(z) = int(255*Frac(z))
MyPalette01(z) = Red01(z) + Green01(z) + Blue01(z)
#MyPalette02
Red02(z) = 255*256*256
Green02(z) = int(165*Frac(z))*256
Blue02(z) = 0
MyPalette02(z) = Red02(z) + Green02(z) + Blue02(z)
# MyPalette03
Red03(z) = int(-95*Frac(z)+255)*256*256
Green03(z) = int(32*Frac(z))*256
Blue03(z) = int(-15*Frac(z)+255)
MyPalette03(z) = Red03(z) + Green03(z) + Blue03(z)
#Red03(z) = int(255*Frac(z))*256*256
#Green03(z) = int(255*Frac(z))*256
#Blue03(z) = int(255*Frac(z))
set object circle at -1,-2,3 size 0.05 front
unset key
set pm3d
set pm3d lighting primary 0.5 specular 0.6
set pm3d ftriangles
set style fill transparent solid 0.75 noborder
set pm3d depthorder
unset colorbox
set view 68, 126
splot $Data01 u 1:2:3:(MyPalette01($3)) w l lc rgb var notitle, \
$Data02 u 1:2:3:(MyPalette02($3)) w l lc rgb var notitle, \
$Data03 u 1:2:3:(MyPalette03($3)) w l lc rgb var notitle
I found how to set multiple styles for each plane in here:
Gnuplot 5.2 splot: Multiple pm3d palette in one plot call
And this is how it looks:
Any Ideas?
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 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:
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'm pretty new to gnuplot, so I'm thankful for every advice.
Right now, I am trying to plot some data using the logscale command. But I don't know why all the xtics disappear when I use the logscale. This is the script I use:
#creates a plot of all the four different loops with a logscale. Fits the functions as well and saves the fitting data
#in a file named fitting.dat
set size 1,1
# set logscale
set logscale y 10
set logscale x 10
#set xlabel and y label
set xlabel "Dimension of Matrix"
set ylabel "time [s]"
#scale plot
set xrange [450:850]
set yrange[0.01:5]
#nothing displayed from fitting
set fit quiet
#position of legend
set key top right
set key horizontal
# guessing the parameters, the fit will be better and we know that the exponent should be \approx 3
b=3
d=3
f=3
h=3
#Define all th four different data fitting functions, asuming f(x) ~ a*x^b
f(x)= a*x**b
g(x)=c*x**d
h(x)=e*x**f
j(x)=g*x**h
#fit the different functions
fit f(x) 'matmul.txt' using 1:2 via a,b
fit g(x) 'matmul.txt' using 1:3 via c,d
fit h(x) 'matmul.txt' using 1:4 via e,f
fit j(x) 'matmul.txt' using 1:5 via g,h
# save the fitting parameters in an extra file
set print 'fitting.dat'
print 'function'
print a,'*x', '**', b , ' rows'
print c,'*x', '**', d , ' cols'
print e,'*x', '**', f , ' intrinsic function'
print g,'*x', '**', h , ' lapack routine'
# plot everything
plot "matmul.txt" u 1:2 t "rows" ,\
"matmul.txt" u 1:3 t "cols" ,\
"matmul.txt" u 1:4 t "intrinsic" ,\
"matmul.txt" u 1:5 t "lapack" ,\
f(x) t sprintf("row:%.2e*x^(%.2f)", a,b),\
g(x) t sprintf("col:%.2e*x^(%.2f)",c,d),\
h(x) t sprintf("int:%.2e*x^(%.2f)",e,f),\
j(x) t sprintf("lap:%.2e*x^(%.2f)",g,h)
#choose output format
set terminal png
set output "time.png"
replot
#now, non-logarithmic plot
#unset logscale
set yrange[0.01:1]
unset logscale
#plot again
plot "matmul.txt" u 1:2 t "rows" ,\
"matmul.txt" u 1:3 t "cols" ,\
"matmul.txt" u 1:4 t "intrinsic" ,\
"matmul.txt" u 1:5 t "lapack" ,\
f(x) t sprintf("col:%.2e*x^(%.2f)", a,b),\
g(x) t sprintf("row:%.2e*x^(%.2f)",c,d),\
h(x) t sprintf("int:%.2e*x^(%.2f)",e,f),\
j(x) t sprintf("lap%.2e*x^(%.2f)",g,h)
My Input file 'matmul.txt' looks like this:
#Dim rows cols intrinsic lapack
500 0.1320E+00 0.1040E+00 0.6800E-01 0.2000E-01
520 0.1400E+00 0.1320E+00 0.5600E-01 0.2000E-01
540 0.1480E+00 0.1400E+00 0.6000E-01 0.3200E-01
560 0.1680E+00 0.1480E+00 0.7200E-01 0.2400E-01
580 0.1800E+00 0.1680E+00 0.6800E-01 0.3200E-01
600 0.1920E+00 0.1960E+00 0.7200E-01 0.3600E-01
620 0.2080E+00 0.2040E+00 0.9600E-01 0.2000E-01
640 0.4000E+00 0.3520E+00 0.8400E-01 0.3200E-01
...
Now, If I run this file, I obtain the following output plot
I don't know why, but the range of the yscale is not correct and the xtics are not displayed. If I plot it without 'logscale', the plot is exactly what I want. Why doesn't this work?
Tics in logarithmic plots are not separated by a constant summand as in 1, 2, 3, ..., they are separated by a constant factor as in 1, 10, 100, ...
This means in your case for the y-axis: You have given the range [0.01:5], leading to tics at 0.01, 0.1, 1 as it is seen in the picture. Above 1, you have minor tics at 2, 3, 4, and 5. 5 is the upper boundary of the graph as specified in the range. To also have a label at this tic, just add it with:
set ytics add (5)
or change the yrange to one of
set yrange [0.01:1]
set yrange [0.01:10]
For your xtics: Labels would be at 1, 10, 100, 1000, ... But your range is from 450 to 850: no labeled xtic inside.
Again, you can set them manually:
set xtics (450, 550, 650, 750, 850)
Your x-axis spans less than a decade and the default major tic frequency is a decade. If you want labeled tics within this range use set xtics (400,500,600,700,800) or whatever you want.
This is all in the documentation, just search for "logscale"