I'm creating a 3D plot via splot
in gnuplot 6.0 and want to manually set the scaling (/aspect ratio) of all three axes.
There are a few related commands, but none of them quite does it:
The scale of the z axis can be set using the fourth argument of the set view
command. This is exactly what I want, but the command works only for the z axis. This is why the title says 'x & y', there needs to be some other way to scale those two.
For a 2D plot, you can set the aspect ratio of the x and y axes with set size ratio <r>
, but this does not work in a 3D plot.
(You can also do set size <xscale>,<yscale>
which works for a 2D plot, but for a 3D plot, it scales the final 2D projection on screen, not the axes.)
The only option for a 3D plot I can find that sets the scaling of x and y is set view equal xy
(or set view equal xyz
), which forces the axes to a 1:1(:1) aspect ratio. But I want to set an aspect ratio that's different from 1:1(:1).
(The only workaround I can think of is scaling the data itself, and then modifying the tick marks to compensate. But it feels like there has to be a better way.)
Here is a simple line with two rectangular 'pulses', one in y and one in z direction. It's plotted with splot "data.csv" with lines
without any further modifications:
This is what data.csv
looks like:
0 0 0
1 0 0
1 3 0
2 3 0
2 0 0
3 0 0
4 0 0
4 0 3
5 0 3
5 0 0
6 0 0
What I want is something like this, where the x:y:z scaling is 5:1:1 (so one unit length on the x axis is displayed 5 times as long as one on the y or z axis, and y and z are scaled equally).
(This was produced via the above workaround by fixing the scaling of the axes via set view equal xyz
and then just scaling the data via splot "data.csv" using ($1*5):2:3 with lines
. But now, of course the tics would display wrong values, so I turned them off.)
Here is a suggestion which might help you a little further.
I guess the "secret" is the following lines, which is basically a mapping to different coordinates (check help nonlinear
).
set view equal xyz
Rx = 5.0
set nonlinear x via x*Rx inverse x/Rx
However, there are a few more things:
set view 60,30, 3,3
: scale x and z by factor 3 to fill the canvas with the graphset xtics 1 scale 4.0 offset -1.0,-0.5
to adjust the length of the xtics and the offset of the xticlabels. Similar for ytics and zticsWhat is not yet clear to me, e.g. in case you want to set a ratio x:y:z
of 5:1:2
set nonlinear z via z*Rz inverse z/Rz
shifts the graph outside the canvas and how to shift it back?Script:
### set visually different xyz ratio than 1:1:1
reset session
$Data <<EOD
0 0 0
1 0 0
1 3 0
2 3 0
2 0 0
3 0 0
4 0 0
4 0 3
5 0 3
5 0 0
6 0 0
EOD
set view equal xyz
set view 60,30, 3,3
Rx = 5.0
Ry = 1.0
Rz = 1.0
set nonlinear x via x*Rx inverse x/Rx
set nonlinear y via y*Ry inverse y/Ry
# set nonlinear z via z*Rz inverse z/Rz # this will lead to a shift of the graph
unset key
set tics out
set xtics 1 scale 4.0 offset -1.0,-0.5
set mxtics Rx
set yrange[-1:4]
set ytics 1 scale 0.333 offset -2.0, 0.5
set ztics 1 scale 1.0
set xyplane relative 0
set grid x,mx,y,z vertical
set border 1+2+4+8+16+32+64+256+512
splot $Data u 1:2:3 w l lw 2 lc "red"
### end of script
Result: