Eunoia

eunoia.EulerFit

Python · python · 0.6.0

Bases: typing.Generic[S]

EulerFit(
    shapes: tuple[S, ...],
    original_values: dict[str, float],
    fitted_values: dict[str, float],
    residuals: dict[str, float],
    region_error: dict[str, float],
    diag_error: float,
    stress: float,
    loss: float,
    container: Container | None = None,
    members: dict[str, list[str]] | None = None,
    plot_data: dict[str, typing.Any] = <factory>
)

Result of fitting an area-proportional Euler diagram.

Attributes

shapes:

Tuple of fitted shapes (one per input set), in the order the sets were first encountered in the input.

original_values:

The values originally passed in. Keys are canonical (sorted) form.

fitted_values:

The fitted areas, expressed in the same scale as original_values (exclusive or inclusive, depending on input).

residuals:

original_values - fitted_values per region.

region_error:

Per-region error (eunoia core's region_error metric, always in per-region exclusive form).

diag_error:

Maximum region error (eulerAPE-style worst-case metric).

stress:

venneuler-style stress metric.

loss:

Final value of the objective the optimizer minimized.

container:

The fitted universe box, when the diagram was fit with complement; otherwise None.

members:

For membership-list input, or array/DataFrame input with ids=, a mapping from canonical region key to the sorted member names in that region; None for area/int input that carries no identities. Enables plot(members=True).

shapes

shapes: tuple[S, ...]

original_values

original_values: dict[str, float]

fitted_values

fitted_values: dict[str, float]

residuals

residuals: dict[str, float]

region_error

region_error: dict[str, float]

diag_error

diag_error: float

stress

stress: float

loss

loss: float

container

container: Container | None = None

members

members: dict[str, list[str]] | None = field(default=None, repr=False)

plot_data

plot_data: dict[str, typing.Any] = field(default_factory=dict, repr=False, compare=False)

plot

plot(
    *,
    ax: Axes | None = None,
    colors: Sequence[Any] | dict[str, Any] | None = None,
    fills: dict[str, dict[str, Any]] | None = None,
    edges: dict[str, Any] | Sequence[dict[str, Any]] | None = None,
    labels: bool | dict[str, Any] | None = None,
    quantities: bool | str | dict[str, Any] | None = None,
    members: bool | dict[str, Any] | None = None,
    glyphs: bool | dict[str, Any] = False,
    legend: bool | dict[str, Any] = False,
    complement: dict[str, Any] | None = None
) -> matplotlib.axes.Axes

Render the fitted diagram with matplotlib.

Parameters

ax:

Existing matplotlib Axes to draw into. If None, a new figure and axes are created via plt.subplots().

colors:

Per-set colors. Either a sequence of colors (one per set, in shape order) or a dict mapping set name to color. None uses the palette global option (matplotlib's tab10 by default; see eunoia.options).

fills:

Per-region fill style overrides. Maps canonical region key to a dict of PathPatch keyword arguments.

edges:

Edge (set boundary) style overrides, as PathPatch keyword arguments. A flat dict is applied uniformly to every set outline; a dict keyed by set name (with kwargs dicts as values) styles each set independently (sets absent from the dict are left at their defaults); a sequence of kwargs dicts assigns one style per set in shape order.

labels:

Set name labels at each set's anchor. None (default) shows them when there is no legend and hides them when a legend is drawn; True or False force them on or off. A dict turns labels on and customizes text and style: either a per-set mapping (keys are set names) whose values are a replacement string, an ax.text kwargs dict (with an optional "text" key for custom text such as mathtext r"$lpha$"), or None or False to hide that set; or a uniform ax.text kwargs dict (no key a set name) applied to every label, e.g. {"fontsize": 14}. Three reserved keys control placement rather than text style: set_position is "inside" (default) or "outside"; set_placement configures exterior set names with margin, angular_steps, and precision; and placement selects the fallback for region blocks—"raycast", "force_directed", "matched", or "elbow"—or a dict with strategy, margin, iterations, min_gap, precision, tether, leader_gap, and leader.

quantities:

Show per-region values. None (default) shows nothing for an EulerFit; for a VennFit it shows the supplied values when the diagram was built with quantities, and nothing otherwise. False always shows nothing; True shows the input values as raw counts. A string selects either the value source ("original", the input values, the default; or "fitted", the fitted areas) or the display type ("counts", raw values; or "percent", each region's share of the total). A dict combines both and adds text styling: ``{"source": "fitted", "type": ["counts", "percent"], "color": "dimgray", "fontsize": 8}. type`` may name both "counts" and "percent" to stack the count above the percentage; any other keys are forwarded to ax.text.

members:

Show each region's member names (available only when the fit carries members, i.e. membership-list input, or array/DataFrame input with ids=; requesting them otherwise raises). None (default) or False shows nothing; True lists every member. A dict adds options and text styling: max caps how many names are listed per region, replacing the rest with a "+N more" line, and any other keys are forwarded to ax.text (e.g. color, fontsize). Long member lists that do not fit inside a region are placed outside with a leader line; use max to keep blocks compact. Set mode="packed" in the dict to pack each name individually inside its region. Packed mode also accepts arrangement, scale, min_scale, gap, seed, precision, and max_attempts.

glyphs:

Draw one equal-sized dot per requested exclusive unit. False (default) disables glyphs; True uses automatic sizing and a uniform arrangement. A dict accepts arrangement ("uniform" or "random"), radius, gap, seed, precision, and max_attempts, plus circle style overrides. Quantities must be finite, nonnegative integers; they are never rounded silently.

legend:

Draw a legend mapping each set to a color swatch, useful when in-diagram labels overlap. True uses matplotlib defaults; a dict is forwarded to ax.legend() (e.g. loc, title, ncol, bbox_to_anchor). When set, labels defaults off.

complement:

Style overrides (Rectangle patch kwargs) for the universe container box, drawn only when the fit has a container. Ignored otherwise.

Returns

matplotlib.axes.Axes

The axes the diagram was drawn into.

plot_plotly

plot_plotly(
    *,
    width: int = 700,
    height: int | None = None,
    colors: Sequence[Any] | dict[str, Any] | None = None,
    fills: dict[str, dict[str, Any]] | None = None,
    edges: dict[str, Any] | Sequence[dict[str, Any]] | None = None,
    labels: bool | dict[str, Any] | None = None,
    quantities: bool | str | dict[str, Any] | None = None,
    members: bool | dict[str, Any] | None = None,
    glyphs: bool | dict[str, Any] = False,
    legend: bool | dict[str, Any] = False,
    complement: dict[str, Any] | None = None,
    hover: bool | str = True
) -> plotly.graph_objects.Figure

Render the fitted diagram to an interactive plotly figure.

The interactive counterpart to plot, requiring the optional eunoia[plotly] extra (pip install 'eunoia[plotly]'). It draws the same area-proportional geometry and size-aware labels, but as a plotly.graph_objects.Figure with per-region hover tooltips -- useful for dense multi-set diagrams where member names do not fit inside small regions.

Most parameters mirror plot (colors, fills, edges, labels, quantities, members, glyphs, legend, and complement); style dicts are read as the analogous plotly properties (the honored keys are colors, alpha, linewidth, and fontsize). The plotly-only parameters are:

Parameters

width:

Figure width in pixels (default 700). The height defaults to whatever preserves the diagram's aspect ratio.

height:

Figure height in pixels. None (default) derives it from width and the diagram's aspect ratio.

hover:

Per-region hover tooltips. True (default) shows each region's key, its count, and -- when the fit carries members -- its member names; "members" or "quantities" restrict the tooltip to one of those; False disables hover.

Returns

plotly.graph_objects.Figure

The interactive figure.