Area
An area graph is a specialized form of the line graph, where instead of simply connecting our data points with a continuous line, we also fill in the region below that line with a solid color.
The parameter x is a matrix of values. Each row of x correspond to
one line in the graph.
The optional parameter base specifies the minimum value on the
y-axis (default to 0).
The optional parameter stacked specifies whether the rows of x are
stacked on top of each other (default value True) or drawn independently (False).
Methods
========================= ================================= Function Description ========================= ================================= area(x, base, stacked) Plot an area figure. ========================= =================================
Description ^^^^^^^^^^^
.. function:: area(x, base!, stacked!)
:param x: Matrix<Float64>
:param base: Float64
:param stacked: Bool
Plot an area figure.
Examples
- Basic area plot, comparing stacked vs. not stacked settings.
::
let Y = matrix<Float64>(
[[1.0, 3.0, 1.0, 2.0],
[5.0, 2.0, 5.0, 6.0],
[3.0, 7.0, 3.0, 1.0]])
let f = gcf()
f.width(f.width() * 2)
subplot(1, 2, 0)
area(Y)
title("Stacked")
subplot(1, 2, 1)
area(Y, stacked: false)
title("Not stacked")
Result:
.. image:: ../../../tests/imgs/area/area_1.png
- Area plot with specified base.
::
let Y = matrix<Float64>(
[[1.0, 3.0, 1.0, 2.0],
[5.0, 2.0, 5.0, 6.0],
[3.0, 7.0, 3.0, 1.0]])
let f = gcf()
f.width(f.width() * 2)
subplot(1, 2, 0)
area(Y, base: -4.0)
title("Stacked")
subplot(1, 2, 1)
area(Y, base: -4.0, stacked: false)
title("Not stacked")
Result:
.. image:: ../../../tests/imgs/area/area_2.png
- Customize line style and face color using handles.
::
let Y = matrix<Float64>(
[[1.0, 3.0, 1.0, 2.0],
[5.0, 2.0, 5.0, 6.0],
[3.0, 7.0, 3.0, 1.0]])
let f = gcf()
f.width(f.width() * 2)
subplot(1, 2, 0)
let h1: Array<Area> = area(Y, base: -4.0)
h1[0].line_style(":").face_color(0.0, 0.0, 0.25, 0.25)
h1[1].line_style(":").face_color(0.0, 0.0, 0.5, 0.5)
h1[2].line_style(":").face_color(0.0, 0.0, 0.75, 0.75)
title("Stacked")
subplot(1, 2, 1)
let h2: Array<Area> = area(Y, base: -4.0, stacked: false)
h2[0].line_style(":").face_color(0.2, 0.0, 0.25, 0.25)
h2[1].line_style(":").face_color(0.2, 0.0, 0.5, 0.5)
h2[2].line_style(":").face_color(0.2, 0.0, 0.75, 0.75)
title("Not stacked")
Result:
.. image:: ../../../tests/imgs/area/area_3.png
- This example shows the stacked vs. not stacked comparison for a different set of data.
::
let Y = matrix<Float64>(
[[1.0, 3.0, 4.0, 0.0],
[2.0, 5.0, 4.0, 7.0],
[6.0, 4.0, 5.0, 3.0]])
let f = gcf()
f.width(f.width() * 2)
subplot(1, 2, 0)
area(Y, base: -4.0)
title("Stacked")
subplot(1, 2, 1)
area(Y, base: -4.0, stacked: false)
title("Not stacked")
Result:
.. image:: ../../../tests/imgs/area/area_4.png