This is documentation for Mathematica 5, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)

Documentation / Mathematica / Add-ons & Links / Standard Packages / Graphics /


You can do most standard plots in three dimensions using the built-in functions Plot3D, ListPlot3D, and ParametricPlot3D. In certain situations, you may want to display your data in a more specialized format, such as a three-dimensional bar chart or a scatter plot. You may also want special effects, such as shadows or projections. In these cases you can use the functions in this package to produce the appropriate plot.

Making three-dimensional bar charts.

This loads the package.

In[1]:= <<Graphics`Graphics3D`

This gives a bar chart made from a two-by-three array of bars with integer height.

In[2]:= BarChart3D[{{1, 2, 3}, {4, 5, 6}}]


The plot can be redisplayed using any option that can be given for a Graphics3D object. This turns off the simulated lighting model and removes the axes and bounding box.

In[3]:= Show[%, Lighting->False,
Boxed->False, Axes->False]


Options for BarChart3D.

BarChart3D has the options XSpacing and YSpacing, which determine the amount of space between bars in the coordinate directions. This must be a number between and ; the default value is 0. BarChart3D returns a Graphics3D object. This means you can give any option that can be specified for a Graphics3D object. BarChart3D has default option settings Axes -> True and BoxRatios -> {1, 1, 1}.

Plotting lists of points in three dimensions.

The built-in function ListPlot will take a list of pairs of coordinates and plot them as points in the plane. To plot a list of triples in three dimensions, you can use ScatterPlot3D. To specify a style for the points or curve being displayed, ScatterPlot3D will also accept the PlotStyle option. ListSurfacePlot3D uses an array of points to generate the vertices of polyhedra.

Here is a list of points in three dimensions.

In[4]:= lpts = Table[{ t Cos[t], t Sin[t], t},
{t, 0, 4Pi, Pi/20}];

This produces a scatter plot of the points. They lie on a conical helix.

In[5]:= ScatterPlot3D[lpts]


This connects the points with a heavy line.

In[6]:= ScatterPlot3D[lpts,
PlotJoined -> True,
PlotStyle -> Thickness[0.03]]


Here is an array of points in three dimensions.

In[7]:= apts = Table[{Cos[t] Cos[u], Sin[t] Cos[u],
Sin[u]}, {t, 0, Pi, Pi/5},
{u, 0, Pi/2, Pi/10}];

The array of points is used to generate vertices in a polygonal mesh. It creates a piece of a sphere.

In[8]:= ListSurfacePlot3D[apts]


Plots with shadows.

ShadowPlot3D and ListShadowPlot3D work exactly like the built-in Plot3D and ListPlot3D, except shadows are drawn.

This puts the shadow in the - plane.

In[9]:= ShadowPlot3D[Sin[x y], {x, 0, 3}, {y, 0, 3}]


Here is another plot with the shadow moved to the top of the bounding box.

In[10]:= ShadowPlot3D[ Exp[-(x^2 + y^2)],
{x, -2, 2}, {y, -2, 2},
ShadowPosition -> 1]


Options for ShadowPlot3D and ListShadowPlot3D.

Shadow has options that determine whether a shadow is drawn in a particular direction. These options are XShadow, YShadow, and ZShadow. The default value for all these options is True. The options XShadowPosition, YShadowPosition, and ZShadowPosition determine whether the projection of the shadow is in the positive or negative coordinate direction. Their default value is -1.

This generates a three-dimensional graphics object using the built-in ParametricPlot3D.

In[11]:= dbell = ParametricPlot3D[
{Sin[t], Sin[2t] Sin[u], Sin[2t] Cos[u]},
{t, -Pi/2, Pi/2}, {u, 0, 2Pi},
Ticks -> None]


This shows the graphics objects with projections from the and directions.

In[12]:= Shadow[dbell, ZShadow -> False]


Here is the same object with the shadow moved to the opposite face of the bounding box.

In[13]:= Shadow[dbell, ZShadow -> False,
XShadowPosition -> 1]


Projections of three-dimensional graphics objects.

This shows the projection of the dumbbell onto the plane normal to its center and the vector {1, 1, 0}.

In[14]:= Show[Project[dbell, {1, 1, 0}]]


Here is the projection onto another plane.

In[15]:= Show[Project[dbell, {0, 1, 0}]]


Changing the basis vectors of the projection plane has the effect of rotating it.

In[16]:= Show[Project[dbell,
{{1, 1, 0}, {0, 0, 1}},
{0, 1, 0}]]


Stacking graphics.

This generates a list of two-dimensional graphics objects. Setting DisplayFunction->Identity stops Plot from rendering the graphics it produces.

In[17]:= gtab = Table[
Plot[x^n, {x, 0, 5},
DisplayFunction -> Identity], {n, 5}]


This shows the graphics stacked in a cube.

In[18]:= Show[StackGraphics[gtab]]


Note that ShadowPlot3D, ListShadowPlot3D, and Shadow all produce and display a three-dimensional graphics object. On the other hand, Project and StackGraphics only produce the graphics object. To display the object, you must use Show.

Using Histogram3D.

Histogram3D is used for plotting categorized bivariate data frequencies. It gives a solid bar chart where the area of each bar is proportional to the area of the bivariate interval defining the respective category, and the height of the bar is proportional to the frequency with which the data fall in that category. Setting FrequencyData -> True specifies that the data given to Histogram3D is to be considered not raw data ready for categorization, but frequency data for categories specified by HistogramCategories.

This loads a package for generating pseudorandom numbers having a multinormal distribution.

In[19]:= Needs["Statistics`MultinormalDistribution`"]

Here is a data set binormally distributed, with zero mean vector and covariance matrix 1, .9, .9, 1.

In[20]:= (binormdist = MultinormalDistribution[{0, 0},
{{1, .9}, {.9, 1}}];
binormdata = RandomArray[binormdist, 100]);

Histogram3D determines the categories automatically, choosing intervals defined by simple numbers.

In[21]:= Histogram3D[binormdata]


Here is a set of data representing the number of items classified according to bivariate intervals. For example, if the cutoffs are and the cutoffs are , then there are 4 data counted in the range and .

In[22]:= countdata =
{{1, 1, 0, 0, 0, 0, 0, 0}, {2, 16, 9, 0, 0, 0, 0, 0},
{0, 4, 10, 8, 2, 0, 0, 0}, {0, 1, 11, 13, 16, 0, 0, 0},
{0, 2, 1, 5, 16, 13, 1, 0}, {0, 0, 0, 2, 16, 8, 9, 0},
{0, 0, 0, 0, 1, 13, 15, 1}, {0, 0, 0, 0, 0, 0, 0, 3}};

The option HistogramCategories can be used to specify the histogram categories, as defined by lists of and cutoffs.

In[23]:= Histogram3D[countdata, FrequencyData->True,
HistogramCategories ->
{{-3, -2, -1, -.5, 0, .5, 1, 2, 3},
{-3, -2, -1, -.5, 0, .5, 1, 2, 3}}]


Special histogram options.

The possible settings for the HistogramCategories option are Automatic, a positive integer , or individual settings for the and coordinates , . If an integer is specified, then the bivariate intervals are chosen to cover the range specified by the HistogramRange option. If ApproximateIntervals -> False, then the histogram will have precisely categories, but if ApproximateIntervals -> True, the requested number of categories may be adjusted in order to give interval boundaries expressed in terms of simple numbers. The individual coordinate settings or may each be Automatic, a positive integer, or a list of cutoffs.

The possible settings for the HistogramRange option are Automatic or a list , , where either or may be set to Automatic or min, max, the latter specifying the lower and upper bounds on the corresponding coordinate of the data to be included in the histogram.

The possible settings for the HistogramScale option are Automatic, True, or a positive number . If Automatic is specified, then the bar heights won't be scaled by the bar cross-sectional areas (yielding frequency densities) unless the areas are unequal. Setting HistogramScale -> True will give frequency densities regardless of bar areas, and setting HistogramScale -> m will scale the bar heights so that the volumes of the solid bars sum to . Setting HistogramScale -> 1 gives a plot approximating the probability density function of the data.

Here HistogramCategories specifies the cutoffs used to categorize the binormally distributed data. The setting Ticks -> IntervalBoundaries puts ticks at the interval boundaries, and the setting HistogramScale -> 1 scales the plot so that the volume of the histogram equals unity.

In[24]:= Histogram3D[binormdata,
HistogramCategories ->
{{-3., -1.5, -.5, 0, .5, 1.5, 3.},
{-3., -1.5, -.5, 0, .5, 1.5, 3.}},
Ticks -> IntervalBoundaries, HistogramScale -> 1]


If you plot a bivariate histogram of frequency data without specifying the categories, the categories are taken to have unit area, i.e., HistogramCategories -> 0, 1, ... , 0, 1, ... .

In[25]:= Histogram3D[countdata, FrequencyData->True]


The Histogram3D function accepts special histogram options; special solid bar chart options, such as SolidBarEdges, SolidBarEdgeStyle, and SolidBarStyle; and standard graphics options like Ticks. Histogram3D accepts special Ticks settings IntervalBoundaries and IntervalCenters.

Settings for the Ticks option of Histogram3D.