Skip to content

flixopt.plot_result

Plot result container for unified plotting API.

This module provides the PlotResult class that wraps plotting outputs across the entire flixopt package, ensuring a consistent interface.

Classes

PlotResult dataclass

PlotResult(data: Dataset, figure: Figure)

Container returned by all plot methods. Holds both data and figure.

This class provides a unified interface for all plotting methods across the flixopt package, enabling consistent method chaining and export options.

Attributes:

Name Type Description
data Dataset

Prepared xarray Dataset used for the plot.

figure Figure

Plotly figure object.

Examples:

Basic usage with chaining:

>>> result = flow_system.statistics.plot.balance('Bus')
>>> result.show().to_html('plot.html')

Accessing underlying data:

>>> result = flow_system.statistics.plot.flows()
>>> df = result.data.to_dataframe()
>>> result.to_csv('data.csv')

Customizing the figure:

>>> result = clustering.plot()
>>> result.update(title='My Custom Title').show()

Functions

show
show() -> PlotResult

Display the figure. Returns self for chaining.

update
update(**layout_kwargs: Any) -> PlotResult

Update figure layout. Returns self for chaining.

Parameters:

Name Type Description Default
**layout_kwargs Any

Arguments passed to plotly's update_layout().

{}

Returns:

Type Description
PlotResult

Self for method chaining.

Examples:

>>> result.update(title='New Title', height=600)
update_traces
update_traces(**trace_kwargs: Any) -> PlotResult

Update figure traces. Returns self for chaining.

Parameters:

Name Type Description Default
**trace_kwargs Any

Arguments passed to plotly's update_traces().

{}

Returns:

Type Description
PlotResult

Self for method chaining.

Examples:

>>> result.update_traces(line_width=2, marker_size=8)
to_html
to_html(path: str | Path) -> PlotResult

Save figure as interactive HTML. Returns self for chaining.

Parameters:

Name Type Description Default
path str | Path

File path for the HTML output.

required

Returns:

Type Description
PlotResult

Self for method chaining.

to_image
to_image(path: str | Path, **kwargs: Any) -> PlotResult

Save figure as static image. Returns self for chaining.

Parameters:

Name Type Description Default
path str | Path

File path for the image (format inferred from extension).

required
**kwargs Any

Additional arguments passed to write_image().

{}

Returns:

Type Description
PlotResult

Self for method chaining.

Examples:

>>> result.to_image('plot.png', scale=2)
>>> result.to_image('plot.svg')
to_csv
to_csv(path: str | Path, **kwargs: Any) -> PlotResult

Export the underlying data to CSV. Returns self for chaining.

Parameters:

Name Type Description Default
path str | Path

File path for the CSV output.

required
**kwargs Any

Additional arguments passed to to_csv().

{}

Returns:

Type Description
PlotResult

Self for method chaining.

to_netcdf
to_netcdf(path: str | Path, **kwargs: Any) -> PlotResult

Export the underlying data to netCDF. Returns self for chaining.

Parameters:

Name Type Description Default
path str | Path

File path for the netCDF output.

required
**kwargs Any

Additional arguments passed to to_netcdf().

{}

Returns:

Type Description
PlotResult

Self for method chaining.