Skip to content

area

Mojo function 🡭

area

fn def area(x: List[Float64], y: List[Float64], step: StepStyle = StepStyle.NONE, theme: Theme = Theme(WHITE, Color(UInt8(30), UInt8(100), UInt8(180), UInt8(255)), Color(UInt8(80), UInt8(80), UInt8(80), UInt8(255)), Color(UInt8(225), UInt8(225), UInt8(225), UInt8(255)), Color(UInt8(40), UInt8(40), UInt8(40), UInt8(255)), SIMD(12), SIMD(3.5), SIMD(2), Int(60), Int(20), Int(20), Int(50), True, False, False, Color(UInt8(240), UInt8(240), UInt8(240), UInt8(255)), Int(3), Color(UInt8(60), UInt8(110), UInt8(200), UInt8(255)), Color(UInt8(235), UInt8(235), UInt8(235), UInt8(255)), Color(UInt8(220), UInt8(90), UInt8(40), UInt8(255)), ColorRamp(), ColorPalette(), SIMD(3), SIMD(15), True, SIMD(1), Int(0), False, Color(UInt8(200), UInt8(60), UInt8(60), UInt8(255)), Color(UInt8(224), UInt8(224), UInt8(224), UInt8(255)), Color(UInt8(120), UInt8(120), UInt8(120), UInt8(255)), Color(UInt8(100), UInt8(100), UInt8(100), UInt8(255)), Color(UInt8(230), UInt8(230), UInt8(230), UInt8(255)), Color(UInt8(255), UInt8(255), UInt8(255), UInt8(255)), UInt8(90), UInt8(160), False, False, SIMD(0), SIMD(18), SIMD(14), Color(UInt8(110), UInt8(110), UInt8(110), UInt8(255)), SIMD(14), Color(UInt8(150), UInt8(150), UInt8(150), UInt8(255)), Color(UInt8(224), UInt8(236), UInt8(246), UInt8(200)), Color(UInt8(255), UInt8(255), UInt8(255), UInt8(255)), True, False, False, True, AxisPosition.EDGE, AxisPosition.EDGE, String("sans-serif"), True, UInt8(90), Int(5), Int(4), Int(130), Int(14), Int(8), Int(14), Int(100), Int(8), SIMD(4), OutputFormat.SVG, Tooltips.AUTO, Missing.DRAW, String("(missing)"), Int(1000), False, LineStyle.SOLID, SIMD(1.5), LineStyle.SOLID, LegendPosition.RIGHT, XAxisLabelRotation.AUTO, TickFormat.AUTO, TickFormat.AUTO), width: Int = Int(640), height: Int = Int(420), title: String = "", x_title: String = "", y_title: String = "") -> Chart[Area]

An area chart: a line chart with the region down to a zero baseline filled in, emphasizing a series’ magnitude and cumulative feel over its exact trend line.

Mark.AREA over continuous x/y, filled down to a zero baseline.

Example:

from dataviz import area
from dataviz import save
from dataviz.core.colors import STEELBLUE
from dataviz import Theme

def main() raises:
    # Illustrative hourly solar output: zero overnight, a small
    # morning cloud dip, and a broad midday production peak.
    var hour: List[Float64] = [
        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
        12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
    ]
    var output_mw: List[Float64] = [
        0, 0, 0, 0, 0, 0, 2, 9, 21, 34, 31, 52,
        63, 68, 66, 59, 48, 35, 20, 8, 1, 0, 0, 0,
    ]

    var c = area(
        hour,
        output_mw,
        title="Illustrative Solar Generation on a Clear Day",
        x_title="Hour of day",
        y_title="Output (MW)",
        theme=Theme(mark_color=STEELBLUE),
    )
    save(c, "docs/src/examples/out_area.svg")

Example (Stepped Area Chart): ```mojo from dataviz import StepStyle, area from dataviz import save from dataviz.core.colors import SEAGREEN from dataviz import Theme

def main() raises:
    # Units in the warehouse change only when a delivery arrives
    # or a shipment leaves, and hold flat in between. A straight
    # top edge would fill in a slow drift between counts that
    # never happened, and the fill would assign area to those
    # invented values; StepStyle.POST holds each count until the
    # day the next one was taken.
    var day: List[Float64] = [
        0.0, 4.0, 7.0, 11.0, 16.0, 20.0, 25.0, 28.0
    ]
    var units: List[Float64] = [
        120.0, 340.0, 300.0, 260.0, 480.0, 430.0, 390.0, 350.0
    ]

    var c = area(
        day,
        units,
        step=StepStyle.POST,
        title="Warehouse Inventory",
        theme=Theme(mark_color=SEAGREEN),
        x_title="Day of month",
        y_title="Units on hand",
    )
    save(c, "docs/src/examples/out_step_area.svg")
```

Args:

  • x (List[Float64]): The continuous x column, one entry per point.
  • y (List[Float64]): The continuous y column; the filled area runs from each point down to zero.
  • step (StepStyle): Step (stairs) interpolation on the fill’s top edge – NONE (the default, straight segments), or PRE/MID/ POST for a quantity that holds constant between samples rather than sliding between them. See StepStyle for which riser placement claims what, and Plot.mark_area() for why only the top edge steps.
  • theme (Theme): Full styling knobs beyond this function’s own parameters (colors, margins, fonts, gridlines, …) – see Theme’s docstring.
  • width (Int): Pixel width of the returned Plot (.size()).
  • height (Int): Pixel height of the returned Plot (.size()).
  • title (String): The chart’s title, shown above the plot.
  • x_title (String): The x-axis caption.
  • y_title (String): The y-axis caption.

Returns:

Chart[Area]: The finished chart – unrendered. Call save(plot, path) to write it (any of .svg/.png/.bmp), or render(plot)/render_svg(plot) for the explicit two-step.

Raises:

fn def area(df: DataFrame, x: String, y: String, step: StepStyle = StepStyle.NONE, theme: Theme = Theme(WHITE, Color(UInt8(30), UInt8(100), UInt8(180), UInt8(255)), Color(UInt8(80), UInt8(80), UInt8(80), UInt8(255)), Color(UInt8(225), UInt8(225), UInt8(225), UInt8(255)), Color(UInt8(40), UInt8(40), UInt8(40), UInt8(255)), SIMD(12), SIMD(3.5), SIMD(2), Int(60), Int(20), Int(20), Int(50), True, False, False, Color(UInt8(240), UInt8(240), UInt8(240), UInt8(255)), Int(3), Color(UInt8(60), UInt8(110), UInt8(200), UInt8(255)), Color(UInt8(235), UInt8(235), UInt8(235), UInt8(255)), Color(UInt8(220), UInt8(90), UInt8(40), UInt8(255)), ColorRamp(), ColorPalette(), SIMD(3), SIMD(15), True, SIMD(1), Int(0), False, Color(UInt8(200), UInt8(60), UInt8(60), UInt8(255)), Color(UInt8(224), UInt8(224), UInt8(224), UInt8(255)), Color(UInt8(120), UInt8(120), UInt8(120), UInt8(255)), Color(UInt8(100), UInt8(100), UInt8(100), UInt8(255)), Color(UInt8(230), UInt8(230), UInt8(230), UInt8(255)), Color(UInt8(255), UInt8(255), UInt8(255), UInt8(255)), UInt8(90), UInt8(160), False, False, SIMD(0), SIMD(18), SIMD(14), Color(UInt8(110), UInt8(110), UInt8(110), UInt8(255)), SIMD(14), Color(UInt8(150), UInt8(150), UInt8(150), UInt8(255)), Color(UInt8(224), UInt8(236), UInt8(246), UInt8(200)), Color(UInt8(255), UInt8(255), UInt8(255), UInt8(255)), True, False, False, True, AxisPosition.EDGE, AxisPosition.EDGE, String("sans-serif"), True, UInt8(90), Int(5), Int(4), Int(130), Int(14), Int(8), Int(14), Int(100), Int(8), SIMD(4), OutputFormat.SVG, Tooltips.AUTO, Missing.DRAW, String("(missing)"), Int(1000), False, LineStyle.SOLID, SIMD(1.5), LineStyle.SOLID, LegendPosition.RIGHT, XAxisLabelRotation.AUTO, TickFormat.AUTO, TickFormat.AUTO), width: Int = Int(640), height: Int = Int(420), title: String = "", x_title: String = "", y_title: String = "") -> Chart[Area]

area() over named columns of a dataframe_mojo DataFrame (#743); the axis titles default to the column names.

The numeric counterpart of line()’s own frame overload, which this mirrors: same channels, same defaults, a filled mark.

Args:

  • df (DataFrame): The frame to read.
  • x (String): The numeric column for the x axis.
  • y (String): The numeric column for the y axis; the filled area runs from each value to the zero baseline.
  • step (StepStyle): Step (stairs) interpolation; see the numeric overload.
  • theme (Theme): Full styling knobs beyond this function’s own parameters.
  • width (Int): Pixel width of the returned Plot (.size()).
  • height (Int): Pixel height of the returned Plot (.size()).
  • title (String): The chart’s title, shown above the plot.
  • x_title (String): The x-axis caption; defaults to x.
  • y_title (String): The y-axis caption; defaults to y.

Returns:

Chart[Area]: The finished chart – unrendered.

Raises:

Error: A named column is missing, is not numeric, or has missing values.

fn def area[x_dtype: DType, y_dtype: DType](x: List[Scalar[x_dtype]], y: List[Scalar[y_dtype]], step: StepStyle = StepStyle.NONE, theme: Theme = Theme(WHITE, Color(UInt8(30), UInt8(100), UInt8(180), UInt8(255)), Color(UInt8(80), UInt8(80), UInt8(80), UInt8(255)), Color(UInt8(225), UInt8(225), UInt8(225), UInt8(255)), Color(UInt8(40), UInt8(40), UInt8(40), UInt8(255)), SIMD(12), SIMD(3.5), SIMD(2), Int(60), Int(20), Int(20), Int(50), True, False, False, Color(UInt8(240), UInt8(240), UInt8(240), UInt8(255)), Int(3), Color(UInt8(60), UInt8(110), UInt8(200), UInt8(255)), Color(UInt8(235), UInt8(235), UInt8(235), UInt8(255)), Color(UInt8(220), UInt8(90), UInt8(40), UInt8(255)), ColorRamp(), ColorPalette(), SIMD(3), SIMD(15), True, SIMD(1), Int(0), False, Color(UInt8(200), UInt8(60), UInt8(60), UInt8(255)), Color(UInt8(224), UInt8(224), UInt8(224), UInt8(255)), Color(UInt8(120), UInt8(120), UInt8(120), UInt8(255)), Color(UInt8(100), UInt8(100), UInt8(100), UInt8(255)), Color(UInt8(230), UInt8(230), UInt8(230), UInt8(255)), Color(UInt8(255), UInt8(255), UInt8(255), UInt8(255)), UInt8(90), UInt8(160), False, False, SIMD(0), SIMD(18), SIMD(14), Color(UInt8(110), UInt8(110), UInt8(110), UInt8(255)), SIMD(14), Color(UInt8(150), UInt8(150), UInt8(150), UInt8(255)), Color(UInt8(224), UInt8(236), UInt8(246), UInt8(200)), Color(UInt8(255), UInt8(255), UInt8(255), UInt8(255)), True, False, False, True, AxisPosition.EDGE, AxisPosition.EDGE, String("sans-serif"), True, UInt8(90), Int(5), Int(4), Int(130), Int(14), Int(8), Int(14), Int(100), Int(8), SIMD(4), OutputFormat.SVG, Tooltips.AUTO, Missing.DRAW, String("(missing)"), Int(1000), False, LineStyle.SOLID, SIMD(1.5), LineStyle.SOLID, LegendPosition.RIGHT, XAxisLabelRotation.AUTO, TickFormat.AUTO, TickFormat.AUTO), width: Int = Int(640), height: Int = Int(420), title: String = "", x_title: String = "", y_title: String = "") -> Chart[Area]

area() generalized over numeric element type; see scatter()’s DType overload above. Delegates to the concrete overload above.

Parameters:

  • x_dtype (DType)
  • y_dtype (DType)

Args:

  • x (List[Scalar[x_dtype]])
  • y (List[Scalar[y_dtype]])
  • step (StepStyle)
  • theme (Theme)
  • width (Int)
  • height (Int)
  • title (String)
  • x_title (String)
  • y_title (String)

Returns:

Chart[Area]

Raises:

fn def area(x: List[Morrow], y: List[Float64], step: StepStyle = StepStyle.NONE, theme: Theme = Theme(WHITE, Color(UInt8(30), UInt8(100), UInt8(180), UInt8(255)), Color(UInt8(80), UInt8(80), UInt8(80), UInt8(255)), Color(UInt8(225), UInt8(225), UInt8(225), UInt8(255)), Color(UInt8(40), UInt8(40), UInt8(40), UInt8(255)), SIMD(12), SIMD(3.5), SIMD(2), Int(60), Int(20), Int(20), Int(50), True, False, False, Color(UInt8(240), UInt8(240), UInt8(240), UInt8(255)), Int(3), Color(UInt8(60), UInt8(110), UInt8(200), UInt8(255)), Color(UInt8(235), UInt8(235), UInt8(235), UInt8(255)), Color(UInt8(220), UInt8(90), UInt8(40), UInt8(255)), ColorRamp(), ColorPalette(), SIMD(3), SIMD(15), True, SIMD(1), Int(0), False, Color(UInt8(200), UInt8(60), UInt8(60), UInt8(255)), Color(UInt8(224), UInt8(224), UInt8(224), UInt8(255)), Color(UInt8(120), UInt8(120), UInt8(120), UInt8(255)), Color(UInt8(100), UInt8(100), UInt8(100), UInt8(255)), Color(UInt8(230), UInt8(230), UInt8(230), UInt8(255)), Color(UInt8(255), UInt8(255), UInt8(255), UInt8(255)), UInt8(90), UInt8(160), False, False, SIMD(0), SIMD(18), SIMD(14), Color(UInt8(110), UInt8(110), UInt8(110), UInt8(255)), SIMD(14), Color(UInt8(150), UInt8(150), UInt8(150), UInt8(255)), Color(UInt8(224), UInt8(236), UInt8(246), UInt8(200)), Color(UInt8(255), UInt8(255), UInt8(255), UInt8(255)), True, False, False, True, AxisPosition.EDGE, AxisPosition.EDGE, String("sans-serif"), True, UInt8(90), Int(5), Int(4), Int(130), Int(14), Int(8), Int(14), Int(100), Int(8), SIMD(4), OutputFormat.SVG, Tooltips.AUTO, Missing.DRAW, String("(missing)"), Int(1000), False, LineStyle.SOLID, SIMD(1.5), LineStyle.SOLID, LegendPosition.RIGHT, XAxisLabelRotation.AUTO, TickFormat.AUTO, TickFormat.AUTO), width: Int = Int(640), height: Int = Int(420), title: String = "", x_title: String = "", y_title: String = "") -> Chart[Area]

area() over a time axis; see line()’s time overload.

Args:

  • x (List[Morrow]): The timestamps, one per point.
  • y (List[Float64]): The continuous y column, one entry per point.
  • step (StepStyle): Step (stairs) interpolation; see the numeric overload.
  • theme (Theme): Visual theme.
  • width (Int): Canvas width in pixels.
  • height (Int): Canvas height in pixels.
  • title (String): Chart title.
  • x_title (String): The x-axis caption.
  • y_title (String): The y-axis caption.

Returns:

Chart[Area]: The finished chart – unrendered.

Raises:

Error: morrow could not convert a value to a timestamp.