plots - Maple Programming Help

Home : Support : Online Help : Graphics : Packages : plots : plots/densityplot

plots

 densityplot
 two-dimensional density plotting

 Calling Sequence densityplot(expr1, x=a..b, y=c..d) densityplot(f, a..b, c..d)

Parameters

 f - function (or set of functions) to be plotted expr1 - expression or set of expressions in x and y a, b - real constants c, d - real constants or procedures defining the bounds of the second dimension (for a transformed problem) x, y - names

Description

 • The densityplot function produces a 2-dimensional plot of a function of 2 variables where color is used to provide information on the value of the function with respect to the two variables.
 • In the first calling sequence, densityplot(expr1, x=a..b, y=c..d), the expression expr1 must be an expression in the names x and y. The first range $a..b$ must evaluate to real constants, while the second range $c..d$ must either evaluate to real constants, or must be single variable functions that, given the value $x$, provide the corresponding endpoint of the range for $y$ as a real constant. They specify the range over which expr1 is plotted.
 In the second calling sequence, densityplot(f, a..b, c..d), f must be a Maple procedure or operator that takes two arguments. Operator notation must be used, that is, the procedure name is given without parameters specified, and the ranges must be given simply in the form $a..b$ and $c..d$, rather than as equations.
 • Any additional arguments are interpreted as options which are specified as equations of the form option = value. For example, the option grid = [m, n] where m and n are positive integers specifies that the plot is to be constructed on an m by n grid at equally spaced points in the ranges a..b and c..d respectively. By default a 49 by 49 grid is used; thus 2401 points are generated, and 2401 colored cells are displayed.
 • The default coloring is SHADING, which produces a gray shading plot. Hue or RGB coloring can be specified via the colorstyle = t option (where t is one of HUE, RGB or SHADING). Additionally, specification of a color option modifies the behavior of the coloring for colorstyle = SHADING or RGB, but has no effect on Hue coloring. The colorscheme option as described on the plot/colorscheme help page can also be used to color density plots.
 • There are three options for controlling the color scaling in a density plot: contrast, brightness, and the detailed option scaletorange. Note: Neither contrast nor brightness can be specified when scaletorange is specified because they adjust the same property: the color scaling range.
 • The densityplot command auto-detects a scaling range that produces a visually pleasing contrast and brightness for the plot, but allows for fine tuning.
 The contrast parameter defaults to $0.5$, and controls the degree of variation based on values in the plot. Raising the contrast results in a plot that has a greater number of values at or closer to the ends of the color range chosen for the plot.
 The brightness parameter also defaults to $0.5$. A higher value produces a plot that is shifted towards the brighter end of the color range, while a lower value produces a plot that is shifted towards the darker end of the color range.
 Note: Specification of contrast=0 restores the behavior of densityplot from Maple 10 and earlier, which is to simply use the minimum and maximum values of the function to determine the color scaling range of the density plot, avoiding the use of the built-in auto-detection.
 • The contrast and brightness parameters work with the auto-detection for a suitable color range to use for the plot, while in contrast the scaletorange option overrides any auto-detection, and specifies the top and bottom end of the value range that corresponds to the color range for the plot. (Note: Values outside the range are pushed to the closest end of the range.)
 For example, specifying $\mathrm{scaletorange}=-5..5$ produces a density plot where function values $<=-5$ are plotted at the lowest value of the color range, and function values $>=5$ are plotted at the highest value of the color range.
 • The exact value of the color scaling range used for the plot is displayed if infolevel[densityplot] is set to 1 or greater. The minimum and maximum function values for the density plot are displayed if infolevel[densityplot] is set to 2 or greater.
 • The restricttoranges parameter is used to restrict the density plot so that it is drawn with the edges exactly on the border of the specified ranges. Note that by default this option is false, and the cells are drawn around each point in the grid, resulting in a plot with 1/2 cell overlap at the borders of the plot.
 • All other options are the same as those found for two dimensional plots (see plot/options).
 • The result of a call to densityplot is a PLOT data structure containing enough information to render the plot. The user may assign a PLOT value to a variable, save it in a file, then read it back in for redisplay. See plot/structure for more information.
 • The command with(plots,densityplot) allows the use of the abbreviated form of this command.

Examples

 > $\mathrm{with}\left(\mathrm{plots}\right):$
 > $\mathrm{densityplot}\left(\mathrm{sin}\left(x+y\right),x=-1..1,y=-1..1\right)$
 > $\mathrm{densityplot}\left(\mathrm{binomial},0..5,0..5,\mathrm{grid}=\left[10,10\right]\right)$
 > $\mathrm{densityplot}\left(\mathrm{sin}\left(xy\right),x=-\mathrm{\pi }..\mathrm{\pi },y=-\mathrm{\pi }..\mathrm{\pi },\mathrm{axes}=\mathrm{boxed},\mathrm{colorstyle}=\mathrm{HUE}\right)$
 > $\mathrm{densityplot}\left(x\mathrm{exp}\left(-{x}^{2}-{y}^{2}\right),x=-2..2,y=-2..2\right)$
 > $\mathrm{densityplot}\left(x\mathrm{exp}\left(-{x}^{2}-{y}^{2}\right),x=-2..2,y=-2..2,\mathrm{color}="Blue"\right)$
 > $\mathrm{densityplot}\left(x\mathrm{exp}\left(-{x}^{2}-{y}^{2}\right),x=-2..2,y=-2..2,\mathrm{colorscheme}=\left["Blue","Green","Orange"\right]\right)$
 > $\mathrm{densityplot}\left({x}^{3},x=-1..1,y={x}^{2}-1..1-{x}^{2}\right)$
 > $\mathrm{densityplot}\left(\left(x,y\right)↦x,0..1,0..\left(x↦1-x\right)\right)$

A plot where scaling is really relevant.  This is the command to create the plot from the Plotting Guide.

 > $\mathrm{densityplot}\left(\frac{x\left({x}^{2}-{y}^{2}\right)}{{\left({x}^{2}+{y}^{2}\right)}^{2}},x=-0.1..0.1,y=-0.1..0.1,\mathrm{grid}=\left[128,128\right],\mathrm{style}=\mathrm{patchnogrid},\mathrm{colour}="Red"\right)$

Adjusting the contrast and scaling to taste:

 > $\mathrm{densityplot}\left(\frac{x\left({x}^{2}-{y}^{2}\right)}{{\left({x}^{2}+{y}^{2}\right)}^{2}},x=-0.1..0.1,y=-0.1..0.1,\mathrm{grid}=\left[128,128\right],\mathrm{style}=\mathrm{patchnogrid},\mathrm{brightness}=0.7,\mathrm{contrast}=0.7\right)$

Use of a specified range:

 > $\mathrm{densityplot}\left(\frac{x\left({x}^{2}-{y}^{2}\right)}{{\left({x}^{2}+{y}^{2}\right)}^{2}},x=-0.1..0.1,y=-0.1..0.1,\mathrm{grid}=\left[128,128\right],\mathrm{style}=\mathrm{patchnogrid},\mathrm{scaletorange}=0..2\right)$

Use of pure max and min (no auto-detection):

 > $\mathrm{densityplot}\left(\frac{x\left({x}^{2}-{y}^{2}\right)}{{\left({x}^{2}+{y}^{2}\right)}^{2}},x=-0.1..0.1,y=-0.1..0.1,\mathrm{grid}=\left[128,128\right],\mathrm{style}=\mathrm{patchnogrid},\mathrm{contrast}=0\right)$

Using 'restricttoranges' produces a plot over 0..5 x 0..5 exactly:

 > $\mathrm{densityplot}\left(\mathrm{sin}\left({x}^{2}+{y}^{2}\right),x=0..5,y=0..5,\mathrm{restricttoranges}=\mathrm{true}\right)$

Plotting a Julia Set.

 > JuliaSet := proc(a, b)  local z1, z2, z1s, z2s, m;  (z1, z2) := (a, b):  z1s := z1^2:  z2s := z2^2;  for m to 30 while z1s+z2s < 4 do    (z1, z2) := (z1s-z2s, 2*z1*z2) + (0, 0.75);    z1s := z1^2;    z2s := z2^2;  end do;  m; end proc:
 > $\mathrm{densityplot}\left(\mathrm{JuliaSet},-1.5..1.5,-1.4..1.4,\mathrm{colorstyle}=\mathrm{HUE},\mathrm{grid}=\left[150,150\right],\mathrm{style}=\mathrm{patchnogrid},\mathrm{axes}=\mathrm{none}\right)$