Skip to content

wire3d

Mojo function 🡭

wire3d

fn def wire3d(df: DataFrame, row: String, column: String, value: String, elev: Float64 = 30, azim: Float64 = -60, 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 = "", subtitle: String = "") -> Chart[Wire3d]

wire3d() over a long-form dataframe_mojo DataFrame (#743): one row per cell, with row and column giving the cell’s coordinates and value its height.

A field is a grid, and a frame is a list of cells, so the rows are pivoted into one. Both axes come out ascending, and become the surface’s own x and y. A cell with no row is missing, not zero: it comes out blank and takes no part in the color limits (#367), which is what lets a table that was never rectangular be drawn as a field.

Args:

  • df (DataFrame): The frame to read.
  • row (String): The numeric column giving each cell’s row coordinate.
  • column (String): The numeric column giving each cell’s column coordinate.
  • value (String): The numeric column holding each cell.
  • elev (Float64): Degrees to look down on the scene from.
  • azim (Float64): Degrees to turn the scene through.
  • 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.
  • subtitle (String): A line under the title.

Returns:

Chart[Wire3d]: The finished chart – unrendered.

Raises:

Error: A named column is missing, is not numeric, the columns differ in length, or a (row, column) pair repeats.

fn def wire3d[dtype: DType](z: List[List[Scalar[dtype]]], x: List[Float64] = List(), y: List[Float64] = List(), elev: Float64 = 30, azim: Float64 = -60, 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(480), title: String = "", subtitle: String = "") -> Chart[Wire3d]

A 3D wireframe: the same height field as surface3d, drawn as the lattice’s own lines with nothing filled in.

Mark.WIRE3D. Nothing is opaque, so the far side of the surface stays visible through the near side – which is the point, and also the cost: on a dense lattice the lines pile up into a thicket that shows no shape at all. Coarsen the grid before reaching for this over surface3d.

Example:

from std.math import sqrt, sin

from dataviz import save, wire3d

def main() raises:
    # Illustrative ripple, on a grid coarse enough to see through.
    var z = List[List[Float64]]()
    for r in range(18):
        var row = List[Float64]()
        for c in range(18):
            var u = (Float64(c) - 9.0) / 3.0
            var v = (Float64(r) - 9.0) / 3.0
            var d = sqrt(u * u + v * v)
            row.append(sin(d * 1.6) / (1.0 + d))
        z.append(row^)

    var c = wire3d(z, title="Illustrative Ripple Drawn as a Lattice")
    save(c, "docs/src/examples/out_wire3d.svg")

Parameters:

  • dtype (DType)

Args:

  • z (List[List[Scalar[dtype]]]): The grid, row-major (z[row][col]), rectangular and at least 2x2. Rows run along y, columns along x.
  • x (List[Float64]): One x coordinate per column of z. Empty (the default) leaves the x axis in grid-index units.
  • y (List[Float64]): One y coordinate per row of z. Empty (the default) leaves the y axis in grid-index units.
  • elev (Float64): Degrees to look down on the scene from, above the x-y plane.
  • azim (Float64): Degrees to turn the scene through, about the z axis.
  • theme (Theme): Full styling knobs beyond this function’s own parameters – 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.
  • subtitle (String): A secondary line shown under the title.

Returns:

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

Raises:

Error: The grid is ragged, or smaller than 2x2.