# eunoia.EulerFit

Python · 0.6.0

[Source](<https://github.com/jolars/eunoia-py/blob/af16491d64a6d1f3b87b8645bd9697593daa0f02/python/eunoia/_models.py>)

Bases: `typing.Generic[S]`

<a id="constructor"></a>

```python
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.

<a id="attributes"></a>

## 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)`.

<a id="shapes"></a>

## `shapes`

```python
shapes: tuple[S, ...]
```

[Source](<https://github.com/jolars/eunoia-py/blob/af16491d64a6d1f3b87b8645bd9697593daa0f02/python/eunoia/_models.py>)

<a id="original_values"></a>

## `original_values`

```python
original_values: dict[str, float]
```

[Source](<https://github.com/jolars/eunoia-py/blob/af16491d64a6d1f3b87b8645bd9697593daa0f02/python/eunoia/_models.py>)

<a id="fitted_values"></a>

## `fitted_values`

```python
fitted_values: dict[str, float]
```

[Source](<https://github.com/jolars/eunoia-py/blob/af16491d64a6d1f3b87b8645bd9697593daa0f02/python/eunoia/_models.py>)

<a id="residuals"></a>

## `residuals`

```python
residuals: dict[str, float]
```

[Source](<https://github.com/jolars/eunoia-py/blob/af16491d64a6d1f3b87b8645bd9697593daa0f02/python/eunoia/_models.py>)

<a id="region_error"></a>

## `region_error`

```python
region_error: dict[str, float]
```

[Source](<https://github.com/jolars/eunoia-py/blob/af16491d64a6d1f3b87b8645bd9697593daa0f02/python/eunoia/_models.py>)

<a id="diag_error"></a>

## `diag_error`

```python
diag_error: float
```

[Source](<https://github.com/jolars/eunoia-py/blob/af16491d64a6d1f3b87b8645bd9697593daa0f02/python/eunoia/_models.py>)

<a id="stress"></a>

## `stress`

```python
stress: float
```

[Source](<https://github.com/jolars/eunoia-py/blob/af16491d64a6d1f3b87b8645bd9697593daa0f02/python/eunoia/_models.py>)

<a id="loss"></a>

## `loss`

```python
loss: float
```

[Source](<https://github.com/jolars/eunoia-py/blob/af16491d64a6d1f3b87b8645bd9697593daa0f02/python/eunoia/_models.py>)

<a id="container"></a>

## `container`

```python
container: Container | None = None
```

[Source](<https://github.com/jolars/eunoia-py/blob/af16491d64a6d1f3b87b8645bd9697593daa0f02/python/eunoia/_models.py>)

<a id="members"></a>

## `members`

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

[Source](<https://github.com/jolars/eunoia-py/blob/af16491d64a6d1f3b87b8645bd9697593daa0f02/python/eunoia/_models.py>)

<a id="plot_data"></a>

## `plot_data`

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

[Source](<https://github.com/jolars/eunoia-py/blob/af16491d64a6d1f3b87b8645bd9697593daa0f02/python/eunoia/_models.py>)

<a id="plot"></a>

## `plot`

```python
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
```

[Source](<https://github.com/jolars/eunoia-py/blob/af16491d64a6d1f3b87b8645bd9697593daa0f02/python/eunoia/_models.py>)

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`](<f80da0cf3188da510c13eb483c4a57de2ec64680c5aa4eed065adf2c00396c30>)).

`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`](<368c6eef5f44d1af6db73a3b8b4a2c7058500ce15acc586ff7b67311c0627c97>); for a [`VennFit`](<f3db9d4c14d408a2963e653df85b6f8608fa6756eee7e138914bd374f632562c>) 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`](<368c6eef5f44d1af6db73a3b8b4a2c7058500ce15acc586ff7b67311c0627c97#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.

<a id="plot_plotly"></a>

## `plot_plotly`

```python
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
```

[Source](<https://github.com/jolars/eunoia-py/blob/af16491d64a6d1f3b87b8645bd9697593daa0f02/python/eunoia/_models.py>)

Render the fitted diagram to an interactive plotly figure.

The interactive counterpart to [`plot`](<368c6eef5f44d1af6db73a3b8b4a2c7058500ce15acc586ff7b67311c0627c97#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`](<368c6eef5f44d1af6db73a3b8b4a2c7058500ce15acc586ff7b67311c0627c97#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`](<368c6eef5f44d1af6db73a3b8b4a2c7058500ce15acc586ff7b67311c0627c97#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.
