Skip to Main Content Skip to Search
Product Documentation

plot::Hatcha hatched area

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.

→ Examples

Calls:

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)

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.

See Also:

plot, plot::copy, plot::Curve2d, plot::Function2d, plot::Sweep

Details:

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)

MuPAD graphics

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

plot::Hatch(sin(x))

Error: No plot::Function2d or plot::Curve2d given. [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)

MuPAD graphics

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)

MuPAD graphics

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)

MuPAD graphics

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))

MuPAD graphics

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))

MuPAD graphics

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)

MuPAD graphics

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

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

MuPAD graphics

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)

MuPAD graphics

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)

MuPAD graphics

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)

MuPAD graphics

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)

MuPAD graphics

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)

MuPAD graphics

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))

MuPAD graphicsimage

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

MuPAD graphicsimage

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))

MuPAD graphics

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS