# `plot`::`Hatch`

Hatched area

MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.

## Syntax

```plot::Hatch(`f1`, `f2`, <`x1 .. x2`>, <`a = amin .. amax`>, `options`)
plot::Hatch(`f1`, <`base`>, <`x1 .. x2`>, <`a = amin .. amax`>, `options`)
plot::Hatch(`c`, <`a = amin .. amax`>, `options`)
```

## Description

`plot::Hatch(f)` hatches the area between the function `f` and the x-axis.

`plot::Hatch(f, base)` hatches the area between the function `f` and the horizontal line y = base.

`plot::Hatch(f, g)` hatches the area between the two functions `f` and `g`.

`plot::Hatch(c)` hatches the area enclosed by the curve `c`.

`plot::Hatch(f, base)` is the hatched area between a function `f` of type `plot::Function2d` and a line parallel to the x-axis with y = base. If `base` is omitted, the area between the function and the x-axis will be hatched (the baseline is assumed to be the x-axis). See Example 1.

`plot::Hatch( f1, f2)` is the hatched area between two functions `f1` and `f2`. See Example 2.

`plot::Hatch(c)` is the hatched area enclosed by a `plot::Curve2d`. A curve is closed automatically by connecting the starting point and the end point. See Example 3.

The hatch may be restricted to the left and to the right by a range `x_..x_`. See Example 4.

The attributes FillColor and FillPattern can be used to change the color and pattern of the hatched area. See Example 5.

### Note

A `plot::Hatch` is only the hatched area without outlining functions or curves! To see the border lines, you need to plot them separately as demonstrated in the examples.

## Attributes

AttributePurposeDefault Value
`AffectViewingBox`influence of objects on the `ViewingBox` of a scene`TRUE`
`AntiAliased`antialiased lines and points?`TRUE`
`Baseline`constant second function delimiting hatch
`Color`the main color`RGB::Red`
`FillColor`color of areas and surfaces`RGB::Red`
`FillPattern`type of area filling`DiagonalLines`
`Frames`the number of frames in an animation`50`
`Function1`first function/curve delimiting hatch
`Function2`second function delimiting hatch
`Legend`makes a legend entry
`LegendText`short explanatory text for legend
`LegendEntry`add this object to the legend?`FALSE`
`Name`the name of a plot object (for browser and legend)
`ParameterEnd`end value of the animation parameter
`ParameterName`name of the animation parameter
`ParameterBegin`initial value of the animation parameter
`ParameterRange`range of the animation parameter
`TimeEnd`end time of the animation`10.0`
`TimeBegin`start time of the animation`0.0`
`TimeRange`the real time span of an animation`0.0` .. `10.0`
`Title`object title
`TitleFont`font of object titles[`" sans-serif "`, `11`]
`TitlePosition`position of object titles
`TitleAlignment`horizontal alignment of titles w.r.t. their coordinates`Center`
`TitlePositionX`position of object titles, x component
`TitlePositionY`position of object titles, y component
`Visible`visibility`TRUE`
`VisibleAfter`object visible after this time value
`VisibleBefore`object visible until this time value
`VisibleFromTo`object visible during this time range
`VisibleAfterEnd`object visible after its animation time ended?`TRUE`
`VisibleBeforeBegin`object visible before its animation time starts?`TRUE`
`XMax`final value of parameter “x”`infinity`
`XMin`initial value of parameter “x”`-infinity`
`XRange`range of parameter “x”`-infinity` .. `infinity`

## Examples

### Example 1

If given a single `plot::Function2d` object, `plot::Hatch` hatches the area between the curve and the x-axis:

```f := plot::Function2d(sin(x), x = -PI..PI): plot(plot::Hatch(f), f)```

Note that `plot::Hatch` requires an object of type `plot::Function2d`, not just a function expression:

`plot::Hatch(sin(x))`
```Error: Missing argument of type 'plot::Function2d' or 'plot::Curve2d'. [plot::Hatch::new] ```

`plot::Hatch` can be asked to hatch the area between a function graph and some constant value (i.e., some line parallel to the x-axis):

`plot(plot::Hatch(f, 1), f)`

For functions with poles, keeping `VerticalAsymptotesVisible` set to `TRUE` is highly recommended:

```f := plot::Function2d(1/(x - 1)): h := plot::Hatch(f): plot(f, h)```

`delete f, h:`

### Example 2

By passing two functions to `plot::Hatch`, we ask for a hatch of the area between the two:

```f := plot::Function2d(sin(x), x = -4 .. 4, Color = RGB::Blue): g := plot::Function2d(cos(2*x), x = -4 .. 4, Color=RGB::Black): h := plot::Hatch(f, g): plot(f, g, h)```

`delete f, g, h:`

### Example 3

`plot::Hatch` can also hatch the inner part of a `plot::Curve2d` object:

```circle := plot::Curve2d([sin(t), cos(t)], t=0..2*PI): plot(circle, plot::Hatch(circle))```

If the curve is not closed, `plot::Hatch` regards the first and last point to be connected:

```circle::UMax := 3*PI/2: plot(circle, plot::Hatch(circle))```

`delete circle:`

### Example 4

By default, `plot::Hatch` extends as far to the left and right as possible without leaving the common definition area of all given functions:

```f := plot::Function2d(sin(x), x = 0 .. 5): g := plot::Function2d(-cos(x), x = -1 .. 4): h := plot::Hatch(f, g): plot(f, g, h)```

You can restrict this range by giving an explicit range of x values:

```h := plot::Hatch(f, g, 1 .. 3): plot(f, g, h)```

However, it is not possible to extend the range beyond the common definition range of both functions:

```h := plot::Hatch(f, g, -1 .. 3): plot(f, g, h)```

The restriction of the x range also works for hatching curve objects:

```c := plot::Curve2d([sin(5*x), cos(7*x)], x = 0 .. 2*PI): h := plot::Hatch(c, 0 .. 1): plot(c, h)```

Note that `plot::Hatch` reacts to the smoothness of the curve. This is one of the reasons why you have to provide a objects instead of expressions for the functions or curves:

```c::AdaptiveMesh := 2: plot(c, h)```

`delete f, g, h, c:`

### Example 5

One of the most useful attributes of `plot::Hatch` is `FillPattern`, which can take one of the values `DiagonalLines` (the default), `FDiagonalLines`, `HorizontalLines`, `VerticalLines`, `CrossedLines`, `XCrossedLines`, or `Solid`:

```f := plot::Function2d(sin(x)): h := plot::Hatch(f, FillPattern = VerticalLines): plot(f, h)```

Another attribute that will often be useful is `FillColor`, to change the color of the hatch. We set the value right in our existing hatch object:

```h::FillPattern := CrossedLines: h::FillColor := RGB::Blue: plot(f, h)```

`delete f, h:`

### Example 6

The function(s) or curve, the baseline, and the restriction of the x range can be animated:

```f := plot::Function2d(sin(x + a), x = -PI..PI, a = 0..2*PI): g := plot::Function2d(cos(x - a), x = -PI..PI, a = 0..4*PI): plot(f, g, plot::Hatch(f, g, x0 .. x0+1, x0 = -PI..3))```

```f := plot::Function2d(sin(a*x), x=-PI..PI, a=0.2..3): plot(f, plot::Hatch(f))```

`delete f, g:`

### Example 7

A “hatch” may also be a solid area fill:

```plot(plot::Hatch( plot::Curve2d([abs(r)*sin(r), abs(r)*cos(r)], r = -PI..PI), FillPattern = Solid, FillColor = RGB::Red, Axes = None))```

## Parameters

 `f1`, `f2` The outlining function(s) of the hatch: objects of type `plot::Function2d`. `f1`, `f2` are equivalent to the attributes `Function1`, `Function2`. `c` The outlining curve of the hatch: a parametrized curve of type `plot::Curve2d`. `c` is equivalent to the attribute `Function1`. `base` The base line of the hatch: a numerical real value or an arithmetical expression of the animation parameter `a`. `base` is equivalent to the attribute `Baseline`. `x1 .. x2` A range on the x-axis limiting the hatch to the left and the right hand side:numerical real values or arithmetical expressions of the animation paramater `a`. `x1` .. `x2` is equivalent to the attributes `XMin`, `XMax`, `XRange`. `a` Animation parameter, specified as `a```` = amin..amax```, where `amin` is the initial parameter value, and `amax` is the final parameter value.

#### Mathematical Modeling with Symbolic Math Toolbox

Get examples and videos