Grid in xzplane - gnuplot

I'm having trouble with displaying a grid in the xzplane. I've changed the position of my z-axis like this:
Now I'd like to have a grid like in the xy-plane in my xz-plane, but since I'm rather new to gnuplot, I couldn't find the correct command.
My code looks like this:
set parametric
set xlabel "Abweichung"
set ylabel "Dosis [%]"
set zlabel "Volumen [%]"
set xrange [-1:1]
set yrange [0:100]
set zrange [0:100]
set xtics 0.2
set ytics 10
set ztics 10
set grid
set border 4095 ls 1 lc rgb "black"
set xtics axis
set ytics axis
set ztics axis
set xzeroaxis lt 1 lw 2 lc rgb "black"
set yzeroaxis lt 1 lw 2 lc rgb "black"
set zzeroaxis lt 1 lw 2 lc rgb "black"
set xyplane 0
splot [t=0:100] 0, t, t

This works in gnuplot 4.6:
set grid ztics
Have a look at this article: http://gnuplot.sourceforge.net/docs_4.2/node188.html
And for a complicated example: http://www.phyast.pitt.edu/~zov1/gnuplot/html/bargraphs.html

Sadly this is currently not supported by the grid command, a feature request should probably be posted.
Anyway, as suggested by mgilson you can manually add the grid-lines with for-loops and the set arrow command. For example adding the following two lines:
set for [x = -10:10:2] arrow from x/10.0, 0, 0 to x/10.0, 0, 100 nohead lt 0
set for [z = 0:100:10] arrow from -1, 0, z to 1, 0, z nohead lt 0
Results in:
You may want to rotate the plot with set view. The divide-by-ten is there because floating-point increment doesn't seem to work.
Or if you wanted the grids to be on the back of the box, do something like this:
set for [x = -10:10:2] arrow from x/10.0, 100, 0 to x/10.0, 100, 100 nohead lt 0
set for [z = 0:100:10] arrow from -1, 100, z to 1, 100, z nohead lt 0
set for [y = 0:100:10] arrow from -1, y, 0 to -1, y, 100 nohead lt 0
set for [z = 0:100:10] arrow from -1, 0, z to -1, 100, z nohead lt 0
Which results in:
A style note
You can replace:
set xtics axis
set ytics axis
set ztics axis
set xzeroaxis lt 1 lw 2 lc rgb "black"
set yzeroaxis lt 1 lw 2 lc rgb "black"
set zzeroaxis lt 1 lw 2 lc rgb "black"
with the equivalent:
set tics axis
set zeroaxis lt 1 lw 2 lc rgb "black"

Related

How to make xtics label color variable in box plot in GNUPlot?

This is my attempt at making the xtics label color match the line color in a box plot in gnuplot:
$DATA << EOD
1 1
2 2
3 3
EOD
set linetype 1 linecolor rgb "red"
set linetype 2 linecolor rgb "green"
set linetype 3 linecolor rgb "blue"
set key off
set boxwidth 0.5
set style fill solid 0.5
set xrange [0:4]
set yrange [0:4]
set xtics ("1" 1) textcolor rgb "red"
set xtics add ("2" 2) textcolor rgb "green"
set xtics add ("3" 3) textcolor rgb "blue"
plot $DATA using 1:2:1 with boxes linecolor variable
But it does not work:
Any idea? Thanks!
I'm not sure whether you can set xtics individually in different colors. So, the following solution sets the xtics as empty lines and you plot your xtics with labels with a certain offset. The disadvantage is that you have to set the y-position here: (0) with offset 0,-1. I hope there are better solutions.
Code:
### "xtic labels" in different colors
reset session
$Data << EOD
1 1
2 2
3 3
EOD
set linetype 1 lc "red"
set linetype 2 lc "green"
set linetype 3 lc "blue"
set key off
set boxwidth 0.5
set style fill solid 0.5
set xrange [0:4]
set yrange [0:4]
set format x "\n" # xtic label empty line
plot $Data u 1:2:1 w boxes lc var, \
'' u 1:(0):1:1 w labels tc var offset 0,-1
### end of code
Alternatively, you could use an offset relative to the graph:
plot $Data u 1:2:1 w boxes lc var, \
'' u 1:(0):1:1 w labels tc var offset 0, graph -0.05
Result:

Plot angle arches, or how to have a custom `range` for successive (re)plot

I'm trying to create a 3d plot of some vectors in a unit sphere with angle arches between some of them.
Here is the current situation. Note: I currently tried only two angle arches but in the end I need some more.
In order to add the arches, I oriented myself on the following tutorial (near the end '3D Case'): http://www.gnuplotting.org/tag/circle/
The problem is, they use urange and vrange to limit the angle of the arch. They can do this, because they only have two angles in the example and not multiple as I have.
So with my limited mathematical and gnuplot knowledge, I tinkered something together which kind of works:
my angle arches attempt
What is kind of ungly is, that the line from the 'end' of my angle arch to 0,0,0is drawn and that even on top of my arrows specified underneath.
Is there a way to plot every arch with different urangeand vrange? Something like:
splot cos(u)*cos(v),cos(u)*sin(v),sin(u) notitle lc rgb "#B0000000" linetype 2,\
[-pi/2:pi/2][0:2*pi] fvx(v),fvy(v),fvz lc rgb "#7878ff" linetype 1,\
[-pi/2:0][0:2*pi] fux(u),fuy(u),fuz(u)
Or is there something I'm completely missing?
Here is my code so far..:
set xrange [-1:1]
set yrange [-1:1]
set zrange [-1:1]
set xyplane at 0 #z axis 0 should be on xy-plane
set parametric
set urange [-pi/2:pi/2]
set vrange [0:2*pi]
set key off
#view schraeg: 32,320
set view 32,320, 1,1
set style arrow 1 linecolor rgb "#FF0000"
set style arrow 2 linecolor rgb "#ff5252"
set style arrow 3 linecolor rgb "#0000FF"
set style arrow 4 linecolor rgb "#0000FF" nohead
set style arrow 6 linecolor rgb "#880000FF" nohead
set style arrow 5 linecolor rgb "#FF0000" nohead
# Angle between m' and x axis
r0 = 0.1
fvx(v) = v<2.5793017540894563 ? r0*cos(v) : 0
fvy(v) = v<2.5793017540894563 ? r0*sin(v) : 0
fvz = 0
# Angle between n and m
r = 0.5
fux(u) = u >= 0.7915660086835659 ? r*cos(u)*cos(2.5793017540894563) : 0
fuy(u) = u >= 0.7915660086835659 ? r*cos(u)*sin(2.5793017540894563) : 0
fuz(u) = u >= 0.7915660086835659 ? r*sin(u) : 0
splot cos(u)*cos(v),cos(u)*sin(v),sin(u) notitle lc rgb "#B0000000" linetype 2,\
fvx(v),fvy(v),fvz lc rgb "#7878ff" linetype 1,\
fux(u),fuy(u),fuz(u)
set arrow from 0,0,0 to 1,0,0 nohead # x axis
set arrow from 0,0,0 to 0,1.5,0 nohead # y axis
set arrow from 0,0,0 to 0,0,2 nohead # z axis
set arrow from 0,0,0 to 0.49999999999999994, 0, 0.8660254037844387 arrowstyle 1 #light
set arrow from 0,0,0 to 0.49999999999999994, 0, 0 arrowstyle 5 #light 1
set arrow from 0.49999999999999994, 0, 0 to 0.49999999999999994, 0, 0.8660254037844387 arrowstyle 5 #light 2
set arrow from 0,0,0 to -0.49999999999999994, 0, 0.8660254037844387 arrowstyle 2 #specular
set arrow from 0,0,0 to -0.6078313957973345, 0.3830222215594889, 0.6955824696430309 arrowstyle 3 #measure
set arrow from 0,0,0 to -0.6078313957973345, 0.3830222215594889, 0 arrowstyle 6 #measure flat
set arrow from 0,0.3830222215594889,0 to -0.6078313957973345, 0.3830222215594889, 0 arrowstyle 6 #measure 1
set arrow from -0.6078313957973345,0,0 to -0.6078313957973345, 0.3830222215594889, 0 arrowstyle 6 #measure 2
set arrow from -0.6078313957973345, 0.3830222215594889, 0 to -0.6078313957973345, 0.3830222215594889, 0.6955824696430309 arrowstyle 4 #measure 3
pause -1
If you cannot specify the range (because you are using a replot approach, which is sensible), then, change the function!
You can make a change of variable to accomodate any other range. Say:
set parametric
set urange [0:pi]
splot 0,0,0 # because internal variables are not initialised else, this will not be a problem in your example.
CoV(u,min,max)=min+(u-GPVAL_U_MIN)*(max-min)/(GPVAL_U_MAX-GPVAL_U_MIN)
splot cos(CoV(u,pi/3,pi/2)),sin(CoV(u,pi/3,pi/2)),0
The CoV (change of variable) uses the ranges of variable u at the time of plotting (Gnuplot variables GPVAL_U_*) to rescale u between the prescribed minimum and maximum values. The ugly splot 0,0,0 might be spared with future versions of gnuplot using stats command, but not yet with version 5.0. Alternatively, one can set his own variables initially:
my_u_min=0.
my_u_max=pi
set urange [my_u_min:my_u_max]
U_MIN(dummy)=(exists("GPVAL_U_MIN")?GPVAL_U_MIN:my_u_min)
U_MAX(dummy)=(exists("GPVAL_U_MAX")?GPVAL_U_MAX:my_u_max)
CoV(u,min,max)=min+(u-U_MIN(0))*(max-min)/(U_MAX(0)-U_MIN(0))

Including solid and dashed contours in gnuplot

i have the following in a gnuplot script:
set pm3d
unset surface
set pm3d map
set style line 1 lt 1 lc rgb "white"
set style line 2 lt 1 lc rgb "white"
set style line 3 lt 1 lc rgb "white"
set style line 4 lt 1 lc rgb "red"
set style line 5 lt 1 lc rgb "blue"
set style line 6 lt 2 lc rgb "white"
set style line 7 lt 2 lc rgb "white"
set style line 8 lt 2 lc rgb "white"
set style line 9 lt 2 lc rgb "white"
set style increment userstyles
set contour base
set cntrparam levels 8
set cntrparam levels discrete -8*0.0004946, -6*0.0004946, -4*0.0004946, -2*0.0004946, -2*0.0004946, 4*0.0004946, 6*0.0004946, 8*0.0004946
set nokey
splot '/data/ltl21/Data/PDB/HDFNI/BlindSurvey/imageresults/spectrum/HDF1map:189.20135-62.20442' u 1:2:3
Such that, i would like to have dashed contours for negative values, and solid contours for positive values. I can change the colour of contours with the above fine, though i want them to all be white, but it doesn't seem to use lt at all, it just picks its own line style and uses that..
Does anyone know how to specify the linetype for individual contours?
Cheers
Same question just appeared to me. Here is a nice workaround I found at http://www.gnuplot.info/faq/faq.html :
gnuplot> # An example. Place your definition in the following line:
gnuplot> f(x,y) = y - x**2 / tan(y)
gnuplot> set contour base
gnuplot> set cntrparam levels discrete 0.0
gnuplot> unset surface
gnuplot> set table ’curve.dat’
gnuplot> splot f(x,y)
gnuplot> unset table
gnuplot> plot ’curve.dat’ w l
Use splot with your standard options. You can save more than one contour in one file. Each contour in the same file will be plotted in the same style.
You can set your plot options as usual: linestyle, linetype etc. That's how I used it:
gnuplot> set cntrparam levels discrete 0,1,2,3
gnuplot> set style line 1 lt 2 lw 4 lc rgb "cyan"
gnuplot> set table 'mycontours.dat'
gnuplot> splot 'mydata.dat' matrix
gnuplot> unset table
gnuplot> plot 'mycontours.dat' ls 1
It returned 4 dashed cyan contours in epslatex. It seems you need to save to different files for different contour styles (or edit the file by hand).
multiplot may be used to address this issue:
set pm3d
unset surface
set pm3d map
set view map
set key center rmargin
set dgrid3d 15,31
set hidden3d
set contour base
set nosurface
set grid lw 1 lc rgb 'gray'
f(x,y) = x*y
set nokey
set cntrparam levels discrete 2, 4, 6, 8
set linetype 1 lc rgb '#0042ad' lw 1.3
set linetype 2 lc rgb '#0060ad' lw 3.1
set linetype 3 lc rgb '#007cad' lw 31
set linetype 4 lc rgb '#0099ad' lw 0.31
set cntrlabel start 25 interval -1 font 'arial, 1'
set style textbox noborder
set multiplot
splot f(x,y) w l title ''
unset pm3d
set linetype 1 lc rgb '#00ada4' lw 2 dashtype 2
# notice how changing 'lw' or 'dashtype' does not have any effect after first use:
set linetype 2 lc rgb '#00ad88' lw 1 dashtype 1
set linetype 3 lc rgb '#00ad6b' lw 3 dashtype 4
set linetype 4 lc rgb '#eeeeee' lw 4 dashtype 3
set cntrparam levels discrete -8, -6, -4, -2
splot f(x,y) w l
unset multiplot
Unsetting pm3d is crucial or it will draw over the lines from the first splot command.

Gnuplot not filling the lines in 3D graphics

I'm ploting with gnuplot but in the 3D graphics some areas are not completed, empty.
The question is simple: how to force it to fill the empty areas ?
Commands that I'm using:
fit (a**-(x**(y**b))) './Tabela_perda_01_MOS_70ms_com_sameq_GOP_30_2_Foot.txt' using 1:2:3:(1) via a,b
set clabel '%8.2f'
set key right
set xlabel "X"
set ylabel "Y"
set zlabel "Z"
set xrange [0:1]
set yrange [2:20]
set zrange [0:1]
set isosample 11,20
set pointsize 0.5
set style line 1 lt 1 lw 2 pt 3 lc rgb "black"
set style line 2 lt 1 lw 1 pt 3 lc rgb "black"
splot "./Tabela_perda_01_MOS_70ms_com_sameq_GOP_30_2_Foot.txt" using 1:2:3 notitle w points ls 1, (a**-(x**(y**b))) w l ls 2

Drawing axis-aligned bounding box (AABB) in gnuplot

I have plotted two vectors (3,3,2), (2,2,1) and want to add an AABB to the first one
to show that the second vector is within the bounds of the first.
Adding set object rectangle from screen 0,0 to screen 3,3 front is not working.
So how can I draw the AABB (or a cuboid with a=3, b=3 and c=2)?
Also how can I put the the scale of the y-axis on the left side.
Still open:
Limit scale of y-axis to left side, and scale of x-axis to bottom front
Add arrows to x-, y- and z-axis
Delete the second x- and y- axis so that there is just one of each left
Gnuscript resource_vec_aabb
set xyplane 0
set grid
set xrange [0:5]
set yrange [0:5]
set zrange [0:5]
splot 'resource_vec_aabb.dat' with vectors filled head lw 2
Data resource_vec_aabb.dat
# Gnuplot .dat file for vectors
0 0 0 3 3 2
0 0 0 2 2 1
UPDATE
set termoption dashed #Needs to be set to draw dashed lines
set border 19 #To set axis (1 + 2 + 16). See: set border help
set xyplane 0
set grid
unset key
my_range = 4
set xrange [0:my_range]
set yrange [0:my_range]
set zrange [0:my_range]
set arrow from graph 0,0,0 to graph 1.05,0,0 size screen 0.025,15,60 \
filled ls 1 linecolor rgb "black"
set arrow from graph 0,0,0 to graph 0,1.05,0 size screen 0.025,15,60 \
filled ls 1 linecolor rgb "black"
set arrow from graph 0,0,0 to graph 0,0,1.05 size screen 0.025,15,60 \
filled ls 1 linecolor rgb "black"
set xtic 1
set ytic 1
set ztic 1
# AABB for 3,3,2
set arrow from 3,0,0 to 3,3,0 nohead linetype 2 linecolor rgb "green"
set arrow from 3,3,0 to 3,3,2 nohead linetype 2 linecolor rgb "green"
set arrow from 0,3,0 to 3,3,0 nohead linetype 2 linecolor rgb "green"
set arrow from 0,3,2 to 3,3,2 nohead linetype 2 linecolor rgb "green"
set arrow from 0,3,0 to 0,3,2 nohead linetype 2 linecolor rgb "green"
set arrow from 0,0,2 to 0,3,2 nohead linetype 2 linecolor rgb "green"
set arrow from 0,0,2 to 3,0,2 nohead linetype 2 linecolor rgb "green"
set arrow from 3,0,0 to 3,0,2 nohead linetype 2 linecolor rgb "green"
set arrow from 3,0,2 to 3,3,2 nohead linetype 2 linecolor rgb "green"
# 2,2,1
set arrow from 2,0,0 to 2,2,0 nohead linetype 2 linecolor rgb "blue"
set arrow from 0,2,0 to 2,2,0 nohead linetype 2 linecolor rgb "blue"
set arrow from 2,2,0 to 2,2,1 nohead linetype 2 linecolor rgb "blue"
set arrow from 0,0,1 to 2,0,1 nohead linetype 2 linecolor rgb "blue"
set arrow from 0,0,1 to 0,2,1 nohead linetype 2 linecolor rgb "blue"
set arrow from 0,2,1 to 2,2,1 nohead linetype 2 linecolor rgb "blue"
set arrow from 2,0,1 to 2,2,1 nohead linetype 2 linecolor rgb "blue"
set arrow from 2,0,0 to 2,0,1 nohead linetype 2 linecolor rgb "blue"
set arrow from 0,2,0 to 0,2,1 nohead linetype 2 linecolor rgb "blue"
set view 40,44,1
splot 'resource_vec_aabb.dat' with vectors filled head lw 2
new output
Here is a suggestion to draw your bounding box with vectors and tic labels at the back y-axis. The bounding boxes are plotted instead of tediously drawn by arrows. There is still room for fine tuning.
Data: SO17363018.dat
# Gnuplot .dat file for vectors
0 0 0 3 3 2
0 0 0 2 2 1
Script: (works for gnuplot>= 4.6.0, March 2012)
### draw bounding box of vectors
reset
FILE = "SO17363018.dat"
set termoption dashed # required for gnuplot4.6 for dashed lines
set xlabel "x-axis" rotate parallel
set ylabel "y-axis" rotate parallel
set xyplane 0
set grid x,y
set xrange [0:5]
set yrange [0:5]
set border 19
set xtics 1 nomirror
set ytics axis
set for [i=1:3] arrow i from graph 0,0,0 to \
graph (1.12*(i==1)), (1.12*(i==2)), (1.12*(i==3)) \
size screen 0.025,15,60 filled ls 1 lc rgb "black"
x0(i,j,k) = ((i==0 ? 0 : i==1 ? k : j)*3+1)
y0(i,j,k) = ((i==0 ? j : i==1 ? 0 : k)*3+2)
z0(i,j,k) = ((i==0 ? k : i==1 ? j : 0)*3+3)
set key noautotitle
set view 61,49, 1.1
splot FILE u 1:2:3:($4-$1):($5-$2):($6-$3) w vec lc rgb "red" lw 2, \
for [c=0:1] for [i=0:2] for [j=0:1] for [k=0:1] FILE \
u (column(x0(i,j,k))):(column(y0(i,j,k))):(column(z0(i,j,k))): \
((i==0)*($4-$1)):((i==1)*($5-$2)):((i==2)*($6-$3)) \
every ::c::c w vec nohead ls 2 lw 1.5 lc c+2
### end of script
For current gnuplot versions 5.x, the script needs to be adapted slightly and you can be shorten the plot command a bit:
dashtype can be specified directly via dt 2, not via ls 2
one for loop less because in 4.6 lc variable doesn't seem to work together with ls 2.
splot FILE u 1:2:3:($4-$1):($5-$2):($6-$3) w vec lc rgb "red" lw 2, \
for [i=0:2] for [j=0:1] for [k=0:1] FILE \
u (column(x0(i,j,k))):(column(y0(i,j,k))):(column(z0(i,j,k))): \
((i==0)*($4-$1)):((i==1)*($5-$2)):((i==2)*($6-$3)):($0+1) \
w vec nohead lw 1.5 dt 2 lc var
Result: (created with gnuplot 4.6.0)

Resources