2D graph of a surface with colors

### 19.5.2 2D graph of a surface with colors

The plotdensity or densityplot command draws the graph of a function of two variables in the plane where the values of z are represented by the rainbow colors.

- plotdensity takes two mandatory arguments and three optional arguments:
  - expr, an expression of two variables.
  - vars, a list of the variables and their ranges.
  - Optionally, z=a..b, the range of z to correspond to the full rainbow (by default, it is deduced from the minimum and maximum value of expr on the discretization.
  - Optionally, xstep, which can be xstep=n to specify the discretization step in the x direction.
  - Optionally, ystep, which can be ystep=m to specify the discretization step in the y direction.

    Instead of xstep and ystep, you could use the option nstep=n to specify the number of points used to graph.

- plotdensity(expr,vars ⟨,z=a..b,xstep,ystep ⟩) draws the graph of expr in the plane where the values of z are represented by the rainbow colors.

##### Remark.

A rectangle representing the scale of colors will be displayed below the graph.

#### Example

plotdensity(x^2-y^2,[x=-2..2,y=-2..2],xstep=0.1,ystep=0.1)