• Aucun résultat trouvé

Special Three-Dimensional Plots

Dans le document Second Edition (Page 171-177)

Three-Dimensional Graphics

5.3 Special Three-Dimensional Plots

The command BarChart3D is the three-dimensional analog of BarChart.

Note: Starting with version 7, BarChart3D can be found in the Mathematica kernel. If you are using version 6, you will find BarChart3D in the package BarCharts` which must be loaded prior to use.

See the Documentation Center for appropriate usage.

BarChart3D[datalist] draws a simple bar graph. datalist is a set of numbers enclosed within braces.

BarChart3D[{datalist1, datalist2,...}] draws a bar graph containing data from multiple data sets. Each data list is a set of numbers enclosed within braces.

If a customized look is desired, there are a variety of options that can be invoked. The format of the command with options becomes

BarChart3D[datalist, options]

BarChart3D[{datalist1, datalist2,...}, options]

Some of the more popular options are:

Chartstyle ãg specifies that style option g should be used to draw the bars. Examples of style options are GrayLevel, Hue, Opacity, RGBColor, and Colors (Red, Blue, etc.).

Chartstyle ã {g1, g2,...} specifies that style options g1, g2, . . . should be used cyclically.

ChartLayout ã "layout" specifies that a layout of type layout should be used to draw the graph.

Examples of layouts are "Stacked", which causes the bars to be stacked on top of each other rather than placed side by side, and "Percentile", which generates a stacked bar chart with the total height of each bar constant at 100%.

BarSpacing controls the spacing between bars and between groups of bars. The default is BarSpacingãAutomatic which allows Mathematica to control the spacing.

BarSpacingãs allows a space of s between bars within each data set. The value of s is measured as a fraction of the width of each bar.

BarSpacing ã {s,t} allows a space of s between bars within each data set and a value of t determines the space between data sets. The values of s ant t are measured as a fraction of the width of each bar.

In each of the preceding BarSpacing commands, the values of s and t may be replaced by one of the predefined symbols None, Tiny, Small, Medium, or Large.

BarOrigin ã edge controls where the bars originate from. The default value of edge is Bottom.

Other acceptable values are Top, Left, and Right.

ChartLabels ã {label1, label2,...} specifies the labeling for each bar corresponding to each value in the data list.

EXAMPLE 17

array={{1,2,3,4},{5,6,7,8},{9,10,11,12}}; g1=BarChart3D[array,ViewPointã{0,–2,2}];

g2=BarChart3D[array,BarSpacingã{.5, 2},ViewPointã{0,–2,2}, ChartLabelsã{"a","b", "c","d"}];

g=GraphicsArray[{g1,g2}]

ListPointPlot3D is the three-dimensional analog of ListPlot, which plots discrete points in a two-dimensional plane.

ListPointPlot3D[list] plots the points in list in a three-dimensional box. list must be a list of sublists, each of which contains three numbers, representing the coordinates of points to be plotted.

By default, ListPointPlot3D uses BoxRatiosã{1,1,.4} and accepts the PlotStyle option discussed in Chapter 4.

In the next example, we generate 50 random points and plot them in three-dimensional space.

EXAMPLE 18

list = Table[RandomInteger[{1,10}],{50},{3}] ← This generates a list of 50 three-element lists of random integers.

ListPointPlot3D[list,BoxRatiosã1]

ListPointPlot3D[list,PlotStyleãPointSize[.02],BoxRatios ã1]

2

ListSurfacePlot3D creates a mesh of polygons constructed from the vertices specified in a list.

ListSurfacePlot3D[list]creates a three-dimensional polygonal mesh from the vertices speci-fied in list, which should be of the form

{{{x11, y11, z11}, {x12, y12, z12},...}, {{x21, y21, z21}, {x22, y22, z22},...},...}

EXAMPLE 19 The following generates a list of 169 vertices on the hyperboloid z=x2y2 and connects them using ListSurfacePlot3D. Note that the list must be flattened before it can be input into the command. (Compare with Problem 5.3.)

list = Table[{x, y, x2 – y2}, {x, – 3, 3,.5}, {y, – 3, 3,.5}];

ListSurfacePlot3D[Flatten[list,1], Axes ã True,BoxRatios ã {1, 1, 1}]

–2

0

2 –2

0 2

–5 0 5

A surface of revolution is a surface obtained by rotating a curve about a given line. Although RevolutionPlot3D, discussed in Section 5.1, can draw surfaces rotated about the z-axis, the com-mand SurfaceOfRevolution offers more flexibility. This comcom-mand was available in previous ver-sions of Mathematica and is now available either in the “legacy” package Graphics` or on the Web at library.wolfram.com/infocenter/MathSource/6824. If downloaded, the package SurfaceOfRevolution.m should be placed in the folder

C:\Program Files\Wolfram Research\Mathematica\x.x\AddOns\LegacyPackages\Graphics Note: A warning will be displayed when this package is loaded. It may be safely ignored. To eliminate this message, execute the following prior to loading the package:

Off[General õ obspkg];

There are various forms of the command with several options.

SurfaceOfRevolution[f[x], {x, xmin, xmax}] generates the surface of revolution obtained by rotating the curve z = f(x) about the z-axis.

SurfaceOfRevolution[f[x], {x, xmin, xmax}, {p, pmin, pmax}] generates the sur-face of revolution obtained by rotating the curve z = f(x) about the z-axis, for θmin ≤θ≤θmax.

SurfaceOfRevolution[{x[t], z[t]}, {t, tmin, tmax}] generates the surface of rev-olution obtained by rotating the curve defined parametrically by x = x(t), z = z(t), about the z-axis.

The following example rotates the curve z = x2 about the z-axis, completely and partially.

EXAMPLE 20

Graphics`

SurfaceOfRevolution[x2, {x, 0, 3}];

SurfaceOfRevolution[x2, {x, 0, 3}, {p, 0, 3o/2}];

The curve z = x2 is rotated about the line connecting the points (0, 0, 0) and (1, 1, 1).

The curve z = x2 is rotated about the line connecting the points (0, 0, 0) and (1, 0, 0).

The option RevolutionAxis allows rotation about axes other than the z-axis.

RevolutionAxis ã {x, z} rotates the curve about an axis formed by connecting the origin to the point (x, z) in the x-z plane.

RevolutionAxis ã {x, y, z} rotates the curve about an axis formed by connecting the origin to the point (x, y, z) in space.

SOLVED PROBLEMS

5.20 Construct a 3 dimensional bar chart depiction of Pascal’s triangle for n = 7.

SOLUTION

Pascal’s triangle is a representation of the binomial coefficients c n k n

k n k

( , ) !

!( )!

= − .

k

0 1 2 3 4 5 6 7

0 1

1 1 1

n 2 1 2 1

3 1 3 3 1

4 1 4 6 4 1

5 1 5 10 10 5 1

6 1 6 15 20 15 6 1

7 1 7 21 35 35 21 7 1

c[n_, k_] = n!

k!(n – k)!;

list=Table[c[n,k],{n,0,7},{k,0,n}];

g=BarChart3D[list, BarSpacing ã {.5, 2}]

5.21 Construct a scatter plot of the points on the helix x=sin2t,y=cos2t z, =t for t between 0 and 10 in increments of .25.

SOLUTION

list = Table[{Sin[2t], Cos[2t], t}, {t, 0, 10, .25}];

ListPointPlot3D[list, PlotStyle ã PointSize[.03], BoxRatiosã{.25,.25,1},Axes ã False]

0 10 20 30

5.22 Construct the surface of revolution obtained by rotating the curve z = sin x, 0 ≤ x ≤ 2 π, about (i) the z-axis and (ii) the x-axis.

SOLUTION

Graphics`

SurfaceOfRevolution[Sin[x],{x,0,2 o},TicksãFalse, AxesLabelã{"x","y","z"}]

SurfaceOfRevolution[Sin[x],{x,0,2 o},RevolutionAxisã{1,0},TicksãFalse, AxesLabelã{"x","y","z"}]

z

x

y

z

y x

5.23 Sketch the surface obtained by rotating the curve z = x2, 0 ≤ x ≤ 1, about the line z = x.

SOLUTION

Graphics`

SurfaceOfRevolution[x2, {x, 0, 1}, RevolutionAxis ã {1, 1}, AxesLabelã{"x","y","z"},Ticks ã False]

Dans le document Second Edition (Page 171-177)