Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
1. A Practical Introduction to Mathematica 176 1.9.6 Contour and Density Plots ContourPlot f, {x, xmin, xmax}, {y, ymin, ymax}] make a contour plot of f as a function of x and y DensityPlot f, {x, xmin, xmax}, {y, ymin, ymax}] make a density plot of f Contour and density plots. This gives a contour plot of the function sin(x) sin(y). In 1]:= ContourPlot Sin x] Sin y], {x, -2, 2}, {y, -2, 2}] 2 1 0 -1 -2 -2 -1 0 1 2 A contour plot gives you essentially a “topographic map” of a function. The contours join points on the surface that have the same height. The default is to have contours corresponding to a sequence of equally spaced z values. Contour plots produced by Mathematica are by default shaded, in such a way that regions with higher z values are lighter. Web sample page from The Mathematica Book, Second Edition, by Stephen Wolfram, published by Addison-Wesley Publishing Company (hardcover ISBN 0-201-51502-4; softcover ISBN 0-201-51507-5). To order Mathematica or this book contact Wolfram Research: [email protected]; http://www.wolfram.com/; 1-800-441-6284. 1991 Wolfram Research, Inc. Permission is hereby granted for web users to make one paper copy of this page for their personal use. Further reproduction, or any copying of machine-readable files (including this one) to any server computer, is strictly prohibited. 1.9 Graphics and Sound 177 option name default value ColorFunction Automatic what colors to use for shading; Hue uses a sequence of hues Contours 10 the total number of contours, or the list of z values for contours PlotRange Automatic the range of values to be included; you can specify {zmin, zmax}, All or Automatic ContourShading True whether to use shading ContourSmoothing None what smoothing to use for contour lines PlotPoints 15 number of evaluation points in each direction Compiled True whether to compile the function being plotted Some options for ContourPlot. The first set can also be used in Show. Particularly if you use a display or printer that does not handle gray levels well, you may find it better to switch off shading in contour plots. In 2]:= Show %, ContourShading -> False] 2 1 0 -1 -2 -2 -1 0 1 2 Web sample page from The Mathematica Book, Second Edition, by Stephen Wolfram, published by Addison-Wesley Publishing Company (hardcover ISBN 0-201-51502-4; softcover ISBN 0-201-51507-5). To order Mathematica or this book contact Wolfram Research: [email protected]; http://www.wolfram.com/; 1-800-441-6284. 1991 Wolfram Research, Inc. Permission is hereby granted for web users to make one paper copy of this page for their personal use. Further reproduction, or any copying of machine-readable files (including this one) to any server computer, is strictly prohibited. 1. A Practical Introduction to Mathematica 178 This increases the density of contours, and tells Mathematica to apply a smoothing algorithm to each contour. In 3]:= Show %, Contours -> 30, ContourSmoothing -> Automatic] 2 1 0 -1 -2 -2 -1 0 1 2 You should realize that if you do not evaluate your function on a fine enough grid, there may be inaccuracies in your contour plot. One point to notice is that whereas a curve generated by Plot may be inaccurate if your function varies too quickly in a particular region, the shape of contours can be inaccurate if your function varies too slowly. A rapidly varying function gives a regular pattern of contours, but a function that is almost flat can give irregular contours. You can often use the ContourSmoothing option to ContourPlot to reduce the visual impact of these irregularities. Density plots show the values of your function at a regular array of points. Lighter regions are higher. In 4]:= DensityPlot Sin x] Sin y], {x, -2, 2}, {y, -2, 2}] 2 1 0 -1 -2 -2 -1 0 1 2 Web sample page from The Mathematica Book, Second Edition, by Stephen Wolfram, published by Addison-Wesley Publishing Company (hardcover ISBN 0-201-51502-4; softcover ISBN 0-201-51507-5). To order Mathematica or this book contact Wolfram Research: [email protected]; http://www.wolfram.com/; 1-800-441-6284. 1991 Wolfram Research, Inc. Permission is hereby granted for web users to make one paper copy of this page for their personal use. Further reproduction, or any copying of machine-readable files (including this one) to any server computer, is strictly prohibited. 1.9 Graphics and Sound 179 You can get rid of the mesh like this. But unless you have a very large number of regions, plots usually look better when you include the mesh. In 5]:= Show %, Mesh -> False] 2 1 0 -1 -2 -2 -1 0 1 2 option name default value ColorFunction Automatic what colors to use for shading; Hue uses a sequence of hues Mesh True whether to draw a mesh PlotPoints 15 number of evaluation points in each direction Compiled True whether to compile the function being plotted Some options for DensityPlot. The first set can also be used in Show. Web sample page from The Mathematica Book, Second Edition, by Stephen Wolfram, published by Addison-Wesley Publishing Company (hardcover ISBN 0-201-51502-4; softcover ISBN 0-201-51507-5). To order Mathematica or this book contact Wolfram Research: [email protected]; http://www.wolfram.com/; 1-800-441-6284. 1991 Wolfram Research, Inc. Permission is hereby granted for web users to make one paper copy of this page for their personal use. Further reproduction, or any copying of machine-readable files (including this one) to any server computer, is strictly prohibited.