polar
Mojo function 🡭
polar
fn def polar(angle: List[Float64], radius: List[Float64], 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 = "", x_title: String = "", y_title: String = "") -> Chart[Polar]A polar-coordinate line plot: a line series where angle and radius place each point around a circle rather than on x/y axes, for cyclical data (compass headings, time of day, seasonal phase) where a circular layout is the natural fit. For several named series on one angular axis, call polar(angle, series_names, series_values) – the overload below – which is the same chart with a legend.
Mark.POLAR over angle (radians, used as given; values beyond
2*pi spiral outward rather than wrapping) and radius (linearly
scaled from [0, max(radius)], zero-anchored at the center; every
value must be non-negative). See _render_polar.
Example:
from std.math import pi
from dataviz import polar
from dataviz import save
def main() raises:
var angle = List[Float64]()
for hour in range(25):
angle.append(2.0 * pi * Float64(hour) / 24.0)
# Illustrative hourly electricity demand (GW); repeat midnight at
# hour 24 so the daily profile closes around the clock.
var demand: List[Float64] = [
22.0, 20.5, 19.4, 18.8, 19.1, 21.7,
26.8, 31.5, 34.2, 35.8, 36.9, 37.4,
36.8, 36.1, 35.7, 36.4, 39.2, 43.8,
46.1, 44.7, 40.3, 34.8, 29.1, 25.0, 22.0,
]
var c = polar(
angle,
demand,
title="Illustrative Weekday Electricity Demand (GW)",
)
save(c, "docs/src/examples/out_polar.svg")Example (Several Series): ```mojo from std.math import pi
from dataviz import polar
from dataviz import save
def main() raises:
var angle = List[Float64]()
for hour in range(25):
angle.append(2.0 * pi * Float64(hour) / 24.0)
# Illustrative station entries (thousands) by hour. The final value
# repeats midnight so each profile closes around the clock.
var weekday: List[Float64] = [
1.2, 0.7, 0.4, 0.3, 0.5, 1.8,
5.6, 10.8, 13.2, 9.4, 6.1, 5.3,
5.0, 5.2, 5.8, 7.1, 9.6, 12.7,
14.1, 11.3, 7.8, 5.0, 3.1, 2.0, 1.2,
]
var weekend: List[Float64] = [
2.0, 1.3, 0.8, 0.5, 0.4, 0.6,
1.1, 2.2, 3.8, 5.5, 7.1, 8.4,
9.0, 9.4, 9.8, 10.1, 10.5, 10.7,
9.9, 8.6, 7.0, 5.2, 3.7, 2.7, 2.0,
]
var names: List[String] = ["Weekday", "Weekend"]
var values: List[List[Float64]] = [
weekday.copy(), weekend.copy(),
]
var c = polar(
angle,
names,
values,
title="Illustrative Hourly Transit Demand (thousands)",
)
save(c, "docs/src/examples/out_polar_several_series.svg")
```
Args:
- angle (
List[Float64]): Radians, used exactly as given and unwrapped – values beyond2*pispiral outward rather than overlapping. - radius (
List[Float64]): Linearly scaled from[0, max(radius)], always zero-anchored at the chart’s center; every value must be non-negative. - theme (
Theme): Full styling knobs beyond this function’s own parameters (colors, margins, fonts, gridlines, …) – seeTheme’s docstring. - width (
Int): Pixel width of the returnedPlot(.size()). - height (
Int): Pixel height of the returnedPlot(.size()). - title (
String): The chart’s title, shown above the plot. - subtitle (
String): A secondary line shown under the title. - x_title (
String): The x-axis caption. - y_title (
String): The y-axis caption.
Returns:
Chart[Polar]: 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 polar(df: DataFrame, angle: String, radius: String, 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 = "", x_title: String = "", y_title: String = "") -> Chart[Polar]polar() over named columns of a dataframe_mojo DataFrame (#743). Each argument names a column instead of holding the values. The axis titles default to the angle and radius column names.
See Plot.encode_frame() for how columns are read and what a
column with missing values does.
Args:
- df (
DataFrame): The frame to read. - angle (
String): The numeric column for this channel. - radius (
String): The numeric column for this channel. - theme (
Theme): See the list overload. - width (
Int): See the list overload. - height (
Int): See the list overload. - title (
String): See the list overload. - subtitle (
String): See the list overload. - x_title (
String): See the list overload. - y_title (
String): See the list overload.
Returns:
Chart[Polar]: The finished chart – unrendered.
Raises:
Error: A named column is missing, has the wrong dtype for its channel, or has missing values.
fn def polar[dtype: DType](angle: List[Scalar[dtype]], radius: List[Scalar[dtype]], 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 = "", x_title: String = "", y_title: String = "") -> Chart[Polar]polar() generalized over numeric element type; see scatter()’s DType overload (continuous.mojo). angle/radius share one dtype. Delegates to the concrete overload above.
Parameters:
- dtype (
DType)
Args:
- angle (
List[Scalar[dtype]]) - radius (
List[Scalar[dtype]]) - theme (
Theme) - width (
Int) - height (
Int) - title (
String) - subtitle (
String) - x_title (
String) - y_title (
String)
Returns:
Chart[Polar]
Raises:
fn def polar(angle: List[Float64], series_names: List[String], series_values: List[List[Float64]], 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 = "", x_title: String = "", y_title: String = "") -> Chart[Polar]polar() for several named series sharing one angular axis: one trace per name, one radius scale across all of them, and a legend keyed by series_names. The single-series form is the overload above (#110).
Mark.POLAR over Plot.encode_polar_series().
Args:
- angle (
List[Float64]): Radians, used exactly as given and unwrapped – shared by every series. - series_names (
List[String]): One trace per name, used as the legend key. - series_values (
List[List[Float64]]):series_values[j]isseries_names[j]’s radius per angle; every value must be non-negative, and every series shares one radius scale. - theme (
Theme): Full styling knobs beyond this function’s own arguments. - width (
Int): Canvas width in pixels. - height (
Int): Canvas height in pixels. - title (
String): Chart title; empty for none. - subtitle (
String): Chart subtitle; empty for none. - x_title (
String): X-axis title; empty for none. - y_title (
String): Y-axis title; empty for none.
Returns:
Chart[Polar]: The finished Plot, ready to render() or save().
Raises:
Error: A series does not match angle’s length or holds a
negative radius (checked at render time).
fn def polar[dtype: DType](angle: List[Float64], series_names: List[String], series_values: List[List[Scalar[dtype]]], 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 = "", x_title: String = "", y_title: String = "") -> Chart[Polar]The multi-series polar() generalized over series_values’ element type; see scatter()’s DType overload (continuous.mojo). angle stays concrete. Delegates to the concrete overload above.
Parameters:
- dtype (
DType)
Args:
- angle (
List[Float64]) - series_names (
List[String]) - series_values (
List[List[Scalar[dtype]]]) - theme (
Theme) - width (
Int) - height (
Int) - title (
String) - subtitle (
String) - x_title (
String) - y_title (
String)
Returns:
Chart[Polar]
Raises: