D7. Turning views
Goal: a 3D plot you turn with the mouse, in a page that needs nothing but a browser.
gnuplot
# a surface to turn with the mouse: the HTML page redraws it from the plot's data at each angle
set terminal html size 640,440
set output 'pd07.html'
set view 60, 30
set pm3d depthorder
set palette viridis
set isosamples 30, 30
set xrange [-3:3]; set yrange [-3:3]
set xlabel 'x'; set ylabel 'y'
splot exp(-(x**2 + y**2)/4)*cos(2*x) with pm3d title 'exp(-r^2/4) cos 2x'Drag in the plot above: a vertical drag turns it about x, a horizontal one about z, and the bottom left corner shows view: X, Z, the set view X, Z that draws it. u goes back to the script's view.
Why it works
- The HTML page carries the plot's 3D scene with the drawing: the box, the tick labels, the lines, points and pm3d quadrangles in their colors. The viewer projects them with gnuplot's transform, as foresight does (at the script's view they land on the drawing within 0.01 px), and paints them farthest first.
- The angles are gnuplot's
set view: type the ones the corner shows into the script to save the view you chose. - The same page zooms the 2D plots (A1): one viewer for every figure.
Try this
- Turn the plot until the peak faces you, read the view in the corner, and set it in the script.
- Save the same script to SVG and PDF: the static figures at the view of
set view.
Pitfalls
- A turned view is a sketch: no hidden lines (
set hidden3d), no contours on the base, no annotations, and the tick labels stay at their places of the script's view. The script's view is the exact one. - Map views (
set view map) do not turn, and a static output (SVG, PDF) cannot: choose the view in the page, then set it in the script.
Reference: 3D views, Interactive Viewer. This is the end of path D: path E is for gnuplot users, the cookbook has one recipe per 3D task.