chord
Mojo function 🡭
chord
fn def chord(df: DataFrame, from_categories: String, to_categories: String, values: String, ring_fraction: Float64 = 0.080000000000000002, 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[Chord]chord() over named columns of a dataframe_mojo DataFrame (#743). Each argument names a column instead of holding the values.
See Plot.encode_frame() for how columns are read and what a
column with missing values does.
Args:
- df (
DataFrame): The frame to read. - from_categories (
String): The string column for this channel. - to_categories (
String): The string column for this channel. - values (
String): The numeric column for this channel. - ring_fraction (
Float64): See the list overload. - 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[Chord]: The finished chart – unrendered.
Raises:
Error: A named column is missing, has the wrong dtype for its channel, or has missing values.
fn def chord[dtype: DType](from_categories: List[String], to_categories: List[String], values: List[Scalar[dtype]], ring_fraction: Float64 = 0.080000000000000002, 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[Chord]A chord diagram: nodes arranged around a circle with arcs between them sized by connection strength, for visualizing many-to-many relationships (flows, correlations, co-occurrences) that would be harder to scan as a matrix of numbers.
Mark.CHORD: ring sectors for every distinct node across
from_categories/to_categories, connected by ribbons sized by
values. See Plot.encode_chord() (plot.mojo) for the data shape.
Example:
from dataviz import chord
from dataviz import save
from dataviz import Theme
def main() raises:
# Illustrative hours contributed between teams during one quarter.
# Repeated teams reveal both hubs and smaller cross-team exchanges.
var from_teams: List[String] = [
"Product", "Product", "Platform", "Platform", "Data", "Data",
"Sales", "Support", "Security", "Security", "Support", "Sales",
]
var to_teams: List[String] = [
"Platform", "Data", "Security", "Support", "Product", "Sales",
"Product", "Platform", "Product", "Data", "Sales", "Support",
]
var collaboration_hours: List[Int] = [
180, 125, 150, 95, 110, 70, 135, 105, 80, 55, 65, 45,
]
var c = chord(
from_teams,
to_teams,
collaboration_hours,
title="Illustrative Cross-Team Project Hours",
)
save(c, "docs/src/examples/out_chord.svg")Parameters:
- dtype (
DType)
Args:
- from_categories (
List[String]): Each flow’s source node, one entry per row. - to_categories (
List[String]): Each flow’s destination node, one entry per row (paired withfrom_categories[i]). - values (
List[Scalar[dtype]]): Each flow’s magnitude, sizing its ribbon; must be non-negative. - ring_fraction (
Float64): The node rim’s thickness as a fraction of the circle radius; defaults to0.08. - 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[Chord]: 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: