{ * Version 1.0 20October2014}{ cmd: help graph3d}

Title

graph3d -- draw three dimensional graphs

Syntax

graph3d var1 var2 var3 [var4] [if] [in] [, options]

Main
colorscheme (string) specifies a color scheme to visualize levels of var2 (or var4 if specified). Supported colorschemes are cr (cyan and red), bcgyr (blue, cyan, green, yellow and red) or fadetogrey (grey shades).

mark displays four different markers according to the magnitude of var2 (or var4 if specified).

equidistance colors and/or markers change equidistantly; default is relative to distance.

wire draws a wire frame that connects all datapoints with the same levels of var1 and var3.

xangle (int 45) specifies the rotation angle about the x-axis with respect to the pivot.

yangle (int 45) specifies the rotation angle about the y-axis with respect to the pivot.

zangle (int 45) specifies the rotation angle about the z-axis with respect to the pivot

xmove (int 0 moves the graph along the x-axis.

ymove (int 0) moves the graph along the y-axis.

zmove (int 0) moves the graph along the z-axis.

xlabel (string) specifies the labelling of the x-axis.

ylabel (string) specifies the labelling of the y-axis.

zlabel (string) specifies the labelling of the z-axis.

xlpos (int 0) specifies the position of the label of the x-axis. See compassdirstyle.

ylpos (int 0) specifies the position of the label of the y-axis. See compassdirstyle.

zlpos (int 0) specifies the position of the label of the z-axis. See compassdirstyle.

xlangle (int 0) specifies the angle of the x-label.

ylangle (int 0) specifies the angle of the y-label.

zlangle (int 0) specifies the angle of the z-label.

xpiv (string x-coordinate of pivot.

ypiv (string) y-coordinate of pivot.

zpiv (string) z-coordinate of pivot.

xcam (real 0) x-position of camera relative to graph.

ycam (real 0) y-position of camera relative to graph.

zcam (real 300) z-position of camera relative to graph.

perspective perspective projection with vanishing point instead of parallel projection.

aspectratio (real 1) aspect ratio of graph, see aspect_option.

scale (real 1) scale of graph (zoom in and out).

piv shows the pivot. When specifying the angles, the graph is rotated around this pivot

cuboid shows a cuboid around the graph.

innergrid additional grid lines on cuboid.

format (string) format of coordinates of cuboid.

markeroptions (string) users can specify all marker_options in parentheses, see example 12 below.

coordinates (string) specifies coordinates of the cuboid that are displayed (1 to 8).

blvertices (int 0) vertices and coordinates of the cuboid are displayed in black.

Description

Description: graph3d draws a three dimensional plot given a dataset of three variables. Moving, scaling, and 360 degree rotating over all axes is fully supported. Parallel projections can be generated, however, the perspective option allows the user to produce a perspective projection of the data. The user simply has to provide the three variables and graph3d will plot small black circles indicating each data point by default.

graph3d can handle even four variables: three variables are plotted along the three axes, the fourth is represented by different colors/shapes of the markers. Three predefined colorschemes allow the user to emphasize how data points move along the specified axis. The marker colors and size can - among other options - be chosen according to the preferences of the user. Using graph3d it is straightforward to produce animations to visualize the big picture.

Typical use of the graph3d command include, to take an example from economics, to depict a budget constraint of a couple household. Other examples are: to use graph3d to illustrate how the utility level of a utility function depends on two arguments or to plot the indifference plane of a utility function that depends on three arguments.

Remarks and tips

graph3d does not adjust the length of the three axes, thus giving the user full flexibility to change the proportion of the axes by manipulating the data. When the magnitudes of the values of the three variables differ substantially (e.g. when plotting two continuous and one categorical variable, see example 16) this can be advisable in order to improve the appearance of the graph.

A simple way to change the perspective of the figure is using the xangle(#), yangle(#) or zangle(#) options, which rotate the figure around the specified axes (see example 2 provided below). Additionally, the perspective can be changed by changing the camera angle or the position of the pivot.

When rotating the cuboid and with axis labels turned on, it might be necessary to adjust the position xlpos(#), ylpos(#) and zlpos(#)) and angles (xlangle(#), ylangle(#) and zlangle(#)) of the axis labels. See examples 15 and 16 below.

Instead of axis value labels graph3d can currently display the coordinates of the cuboid coordinates. Specify the points of the cuboid (up to 8), whose coordinates you want to display. See examples 13 and 14.

When three (four) variables and a colorscheme or the mark option are specified, the third (fourth) variable determines the marker/color.

The wire command works best, when there is only one observations for each value of var1 and var3. Using wire with a very large dataset can result in the error "too many sersets". In this case it is not possible to use the wire function.

Examples: colorful 3D-Plots of random data

Setup

clear

set obs 630

gen x = int((_n - mod(_n-1,30) -1 ) /30 )

gen z = mod(_n-1,30)

gen y = normalden(x,10,3)*normalden(z,15,5)*10000

gen w = x*z

1. Default 3D-Plot

graph3d x y z

2. Default 3D-Plot rotated by 70 degree about the x-axis

graph3d x y z, xang(75)

3. Wireframe 3D-Plot

graph3d x y z, wire

4. Two-colored 3D-Plot

graph3d x y z, colorscheme(cr)

5. Plot where a fourth variable determines the color of the markers

graph3d x y z w, colorscheme(cr)

6. Plot where first variable determines the color of the markers

graph3d x y z x, colorscheme(cr)

7. Two-colored 3D-Plot with changing markers

graph3d x y z, mark colorscheme(cr)

8. Equidistantly two-colored 3D-Plot with changing markers

graph3d x y z, equi mark colorscheme(cr)

9. Five-colored 3D-Plot with changing markers

graph3d x y z, mark colorscheme(bcgyr)

10. Grey scale 3D-Plot with changing markers

graph3d x y z, mark colorscheme(fade)

11. Perspective 3D-Plot

graph3d x y z, ycam(-4) zcam(-18) cuboid innergrid blv perspective colorscheme(bcgyr)

12. Marker options specified by user

graph3d x y z, markeroptions(mcolor(red) msymbol(diamond))

13. Plot with cuboid and coordinates of three points

graph3d x y z, cuboid coordinates(5 2 8)

14. Plot with cuboid and coordinates of eight points displayed in black

graph3d x y z, cuboid coordinates(all) blv

15. Plot with cuboid and user defined axis labels, rotated by 80 degree about the x axis.

graph3d x y z, cuboid xangle(80) xlabel(test1) xlangle (330) xlpos(9) yl(test 2) ylangle(90) ylpos(3) zlabel(test 3) zlangle(33) zlpos(11)

16. Ploting two continuous and one categorial variable.

clear

sysuse citytemp.dta

gen reg = region * 1000

graph3d heatdd cooldd reg, cuboid innergrid colorscheme(bcgyr) xang(15) yang(80) xlab("Heating degree days") ylab("Cooling degree days") zlab("Census Region") xlang(315) ylang(90) zlang(0) xlpos(11) ylpos(3) zlpos(11)

more examples

Authors

Robin Jessen
Freie Universität Berlin
robin.jessen@fu-berlin.de

Davud Rostam-Afschar
Freie Universität Berlin and DIW Berlin
davud.rostam-afschar@fu-berlin.de

See also

Surface by Adrian Mander