# Density and Contour Plots

DensityPlot[f,{x,x_{min},x_{max}},{y,y_{min},y_{max}}] | |

make a density plot of f | |

ContourPlot[f,{x,x_{min},x_{max}},{y,y_{min},y_{max}}] | |

make a contour plot of f as a function of x and y |

In[1]:= |

Out[1]= |

option name | default value | |

ColorFunction | Automatic | what colors to use for shading; Hue uses a sequence of hues |

Mesh | None | whether to draw a mesh |

PlotPoints | Automatic | number of initial sample points in each direction |

MaxRecursion | Automatic | the maximum number of recursive subdivision steps to do |

Some options for DensityPlot.

In[2]:= |

Out[2]= |

In a density plot, the color of each point represents the value at that point of the function being plotted. By default, the color ranges from black to white through intermediate shades of blue as the value of the function increases. In general, however, you can specify other "color maps" for the relation between the value at a point and its color. The option ColorFunction allows you to specify a function which is applied to the function value to find the color at any point. The color function may return any *Mathematica* color directive, such as GrayLevel, Hue, or RGBColor. A common setting to use is ColorFunction->Hue.

In[3]:= |

Out[3]= |

A significant resource for customized color functions is the ColorData function. ColorData provides many customized sets of colors which can be used directly by ColorFunction.

In[4]:= |

Out[4]= |

In[5]:= |

Out[5]= |

In[6]:= |

Out[6]= |

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.

option name | default value | |

ColorFunction | Automatic | what colors to use for shading; Hue uses a sequence of hues |

Contours | Automatic | the total number of contours, or the list of z values for contours |

PlotRange | {Full,Full,Automatic} | the range of values to be included; you can specify , All or Automatic, or a list |

ContourShading | Automatic | how to shade the regions; None leaves the regions blank, or a list of colors can be provided |

PlotPoints | Automatic | number of initial sample points in each direction |

MaxRecursion | Automatic | the maximum number of recursive subdivision steps to do |

Some options for ContourPlot.

In[7]:= |

Out[7]= |

In[8]:= |

Out[8]= |

Both DensityPlot and ContourPlot use an adaptive algorithm that subdivides parts of the plot region to obtain more sample points for a smoother representation of the function you are plotting. Because the number of sample points is always finite, however, it is possible that features of your function will sometimes be missed. When necessary, you can increase the number of sample points by increasing the values of the PlotPoints and MaxRecursion options.

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 generated by ContourPlot 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 typically overcome this by increasing the value of PlotPoints or MaxRecursion.