Plotting
PlotAccessor
¶
PlotAccessor(n: Network)
Accessor for plotting statistics.
The class inherits from StatisticsAccessor and provides the same statistic functions, but returns a StatisticPlotter object instead of a DataFrame.
Methods:
-
__call__–Alias for pypsa.Network.plot.map.
-
map–Plot the network buses and lines using matplotlib and cartopy.
-
iplot–Plot the network buses and lines interactively using plotly.
-
explore–Create an interactive map of the PyPSA network using Pydeck.
pypsa.Network.plot.__call__
¶
__call__(*args: Any, **kwargs: Any) -> Any
Alias for pypsa.Network.plot.map.
pypsa.Network.plot.map
¶
map(*args: Any, **kwargs: Any) -> Any
Plot the network buses and lines using matplotlib and cartopy.
Parameters:
-
boundaries(list / tuple, default:None) –Boundaries of the plot in format [x1, x2, y1, y2]
-
ax(matplotlib.pyplot.Axes, defaults to None) –Axis to plot on. Defaults to plt.gca() if geomap is False, otherwise to plt.axes(projection=projection).
-
geomap–Switch to use Cartopy and draw geographical features. If string is passed, it will be used as a resolution argument, valid options are '10m', '50m' and '110m'.
-
geomap_resolution(str, default:'50m') –Resolution of the geomap, only valid if cartopy is installed. Valid options are '10m', '50m' and '110m'.
-
projection–Define the projection of your geomap, only valid if cartopy is installed. If None (default) is passed the projection for cartopy is set to cartopy.crs.PlateCarree
-
geomap_color(dict / bool, default:None) –Specify colors to paint land and sea areas in. If True, it defaults to
{'ocean': 'lightblue', 'land': 'whitesmoke'}. If no dictionary is provided, colors are white. If False, no geographical features are plotted. -
title(string, default:"") –Graph title
-
branch_components(list, default:n.branch_components) –Branch components to be plotted
-
bus_size(float / dict / Series) –Sizes of bus points, defaults to 1e-2. If a multiindexed Series is passed, the function will draw pies for each bus (first index level) with segments of different color (second index level). Such a Series is ob- tained by e.g. n.generators.groupby(['bus', 'carrier']).p_nom.sum()
-
bus_split_circle(bool, default:False) –Draw half circles if bus_size is a pandas.Series with a Multiindex. If set to true, the upper half circle per bus then includes all positive values of the series, the lower half circle all negative values. Defaults to False.
-
bus_color(str / dict / Series) –Colors for the buses, defaults to "cadetblue". If bus_size is a pandas.Series with a Multiindex, bus_color defaults to the n.carriers['color'] column.
-
bus_cmap(Colormap / str) –If bus_color are floats, this color map will assign the colors
-
bus_cmap_norm(Normalize) –The norm applied to the bus_cmap
-
bus_alpha(float / dict / Series) –Adds alpha channel to buses, defaults to 1
-
geometry(bool, default:False) –Whether to use the geometry column of the branch components
-
flow(Callable) –Function to calculate the flow for each branch component.
-
auto_scale_branches(bool) –Whether to auto scale the flow and branch sizes. If true, the function uses a rough auto-scaling when plotting flows as well as it creates a LineCollection with widths in data units. If false, the function does not scale the flow and branch sizes and creates a PatchCollection with widths in display units. The latter is useful for plotting consistent branch widths and flows in different zoom levels.
Other Parameters:
-
line_flow(str / callable / dict / Series / snapshots) –Flow to be for each line branch. If an element of n.snapshots is given, the flow at this timestamp will be displayed. If an aggregation function is given, is will be applied to the total network flow via pandas.DataFrame.agg (accepts also function names). Otherwise flows can be specified by passing a pandas Series. Use the corresponding width argument to adjust size of the flow arrows.
-
line_color(str / Series) –Colors for the lines, defaults to 'rosybrown'.
-
line_cmap(Colormap / str | dict) –If line_color are floats, this color map will assign the colors.
-
line_cmap_norm(Normalize) –The norm applied to the line_cmap.
-
line_alpha(str / Series) –Alpha for the lines, defaults to 1.
-
line_width(dict / Series) –Widths of lines, defaults to 1.5
-
link_flow(str / callable / dict / Series / snapshots) –Flow to be for each link branch. See line_flow for more information.
-
link_color(str / Series) –Colors for the links, defaults to 'darkseagreen'.
-
link_cmap(Colormap / str | dict) –If link_color are floats, this color map will assign the colors.
-
link_cmap_norm(mcolors.Normalize|matplotlib.colors.*Norm) –The norm applied to the link_cmap.
-
link_alpha(str / Series) –Alpha for the links, defaults to 1.
-
link_width(dict / Series) –Widths of links, defaults to 1.5
-
transformer_flow(str / callable / dict / Series / snapshots) –Flow to be for each transformer branch. See line_flow for more information.
-
transformer_color(str / Series) –Colors for the transfomer, defaults to 'orange'.
-
transformer_cmap(Colormap / str | dict) –If transformer_color are floats, this color map will assign the colors.
-
transformer_cmap_norm(matplotlib.colors.Normalize|matplotlib.colors.*Norm) –The norm applied to the transformer_cmap.
-
transformer_alpha(str / Series) –Alpha for the transfomer, defaults to 1.
-
transformer_width(dict / Series) –Widths of transformer, defaults to 1.5
Returns:
-
dict(collections of matplotlib objects) –2D dictinary with the following keys: - 'nodes' - 'Bus': Collection of bus points - 'branches' (for each branch component) - 'lines': Collection of line branches - 'links': Collection of link branches - 'transformers': Collection of transformer branches - 'flows' (for each branch component) - 'lines': Collection of line flows - 'links': Collection of link flows - 'transformers': Collection of transformer flows
pypsa.Network.plot.iplot
¶
iplot(*args: Any, **kwargs: Any) -> Any
Plot the network buses and lines interactively using plotly.
Parameters:
-
n(Network) –The network to plot.
-
fig(dict, default:None) –If not None, figure is built upon this fig.
-
bus_color(dict / Series) –Colors for the buses, defaults to "cadetblue". If bus_size is a pandas.Series with a Multiindex, bus_color defaults to the n.c.carriers.static['color'] column.
-
bus_alpha(float) –Add alpha channel to buses, defaults to 1.
-
bus_size(float / Series) –Sizes of bus points, defaults to 10.
-
bus_cmap(Colormap / str) –If bus_color are floats, this color map will assign the colors
-
bus_colorbar(dict) –Plotly colorbar, e.g. {'title' : 'my colorbar'}
-
bus_text(Series) –Text for each bus, defaults to bus names
-
line_color(str / Series) –Colors for the lines, defaults to 'rosybrown'.
-
link_color(str / Series) –Colors for the links, defaults to 'darkseagreen'.
-
transformer_color(str / Series) –Colors for the transfomer, defaults to 'orange'.
-
line_width(dict / Series) –Widths of lines, defaults to 1.5
-
link_width(dict / Series) –Widths of links, defaults to 1.5
-
transformer_width(dict / Series) –Widths of transformer, defaults to 1.5
-
line_text(Series) –Text for lines, defaults to line names.
-
link_text(Series) –Text for links, defaults to link names.
-
transformer_text(Series) –Text for transformers, defaults to transformer names.
-
layouter(networkx.drawing.layout function, default:None) – -
title(string) –Graph title
-
size(None | tuple) –Tuple specifying width and height of figure; e.g. (width, heigh).
-
branch_components(list of str) –Branch components to be plotted, defaults to Line and Link.
-
iplot(bool, default:True) –Automatically do an interactive plot of the figure.
-
jitter(None | float) –Amount of random noise to add to bus positions to distinguish overlapping buses
-
mapbox(bool, default:False) –Switch to use Mapbox.
-
mapbox_style(str, default:'open-street-map') –Define the mapbox layout style of the interactive plot. If this is set to a mapbox layout, the argument
mapbox_tokenmust be a valid Mapbox API access token.Valid open layouts are: open-street-map, white-bg, carto-positron, carto-darkmatter, stamen-terrain, stamen-toner, stamen-watercolor
Valid mapbox layouts are: basic, streets, outdoors, light, dark, satellite, satellite-streets
-
mapbox_token(string) –Mapbox API access token. Obtain from
https://www.mapbox.com. Can also be included in mapbox_parameters asaccesstoken=mapbox_token. -
mapbox_parameters(dict) –Configuration parameters of the Mapbox layout. E.g. {"bearing": 5, "pitch": 10, "zoom": 1, "style": 'dark'}.
Returns:
-
fig(dictionary for plotly figure) –
pypsa.Network.plot.explore
¶
explore(*args: Any, **kwargs: Any) -> Any
Create an interactive map of the PyPSA network using Pydeck.
Parameters:
-
branch_width_factor(float, default:1.0) –Branch widths are scaled by this factor.
-
bus_size(float / dict / Series) –Sizes of bus points in km² (corresponds to circle area), defaults to 25 km².
-
bus_size_factor(float, default:1.0) –Bus sizes are scaled by this factor.
-
bus_split_circle(bool, default:False) –Draw half circles if bus_size is a pandas.Series with a Multiindex. If set to true, the upper half circle per bus then includes all positive values of the series, the lower half circle all negative values. Defaults to False.
-
bus_color(str / dict / Series / None) –Colors for the buses, defaults to "cadetblue". If bus_size is a pandas.Series with a Multiindex, bus_color defaults to the n.c.carriers.static['color'] column.
-
bus_cmap(Colormap / str, default:'Reds') –If bus_color are floats, this color map will assign the colors.
-
bus_cmap_norm(Normalize / None) –Normalization for bus_cmap, defaults to None.
-
bus_alpha(float / dict / Series) –Add alpha channel to buses, defaults to 0.9.
-
line_flow(float / dict / Series, default:0) –Series of line flows indexed by line names, defaults to 0. If 0, no arrows will be created. If a float is provided, it will be used as a constant flow for all lines.
-
line_color(str / dict / Series) –Colors for the lines, defaults to 'rosybrown'.
-
line_alpha(float / dict / Series) –Add alpha channel to lines, defaults to 0.9.
-
line_width(float / dict / Series, default:2) –Widths of line component in km.
-
link_flow(float / dict / Series, default:0) –Series of link flows indexed by link names, defaults to 0. If 0, no arrows will be created. If a float is provided, it will be used as a constant flow for all links.
-
link_color(str / dict / Series) –Colors for the links, defaults to 'darkseagreen'.
-
link_alpha(float / dict / Series) –Add alpha channel to links, defaults to 0.9.
-
link_width(float / dict / Series, default:2) –Widths of link component in km.
-
tooltip(bool, default:True) –Whether to add a tooltip to the bus layer.
Other Parameters:
-
branch_components((list, set)) –Branch components to be plotted.
-
branch_width_max(float) –Maximum width of branch component in km when
auto_scaleis True. -
bus_size_max(float) –Maximum area size of bus component in km² when
auto_scaleis True. -
line_cmap(Colormap / str) –If line_color are floats, this color map will assign the colors.
-
line_cmap_norm(Normalize) –The norm applied to the line_cmap.
-
link_cmap(Colormap / str) –If link_color are floats, this color map will assign the colors.
-
link_cmap_norm(mcolors.Normalize|matplotlib.colors.*Norm) –The norm applied to the link_cmap.
-
transformer_flow(float / dict / Series) –Series of transformer flows indexed by transformer names, defaults to 0. If 0, no arrows will be created. If a float is provided, it will be used as a constant flow for all transformers.
-
transformer_color(str / dict / Series) –Colors for the transformers, defaults to 'orange'.
-
transformer_cmap(Colormap / str) –If transformer_color are floats, this color map will assign the colors.
-
transformer_cmap_norm(matplotlib.colors.Normalize|matplotlib.colors.*Norm) –The norm applied to the transformer_cmap.
-
transformer_alpha(float / dict / Series) –Add alpha channel to transformers, defaults to 0.9.
-
transformer_width(float / dict / Series) –Widths of transformer in km.
-
arrow_size_factor(float) –Multiplier on branch flows to scale the arrow size.
-
arrow_color(str / dict / Series | None) –Colors for the arrows. If not specified, defaults to the same colors as the respective branch component.
-
arrow_cmap(str / Colormap) –Colormap to use if arrow_color is a numeric pandas.Series.
-
arrow_cmap_norm(Normalize) –Normalization to use if arrow_color is a numeric pandas.Series.
-
arrow_alpha(float / dict / Series) –Add alpha channel to arrows, defaults to 0.9.
-
bus_columns(list) –List of bus columns to include. Specify additional columns to include in the tooltip.
-
line_columns(list) –List of line columns to include. If None, only the bus0 and bus1 columns are used. Specify additional columns to include in the tooltip.
-
link_columns(list) –List of link columns to include. If None, only the bus0 and bus1 columns are used. Specify additional columns to include in the tooltip.
-
transformer_columns(list) –List of transformer columns to include. If None, only the bus0 and bus1 columns are used. Specify additional columns to include in the tooltip.
-
geomap(bool) –Whether to add a geomap layer to the plot.
-
geomap_alpha(float) –Alpha transparency for the geomap features.
-
geomap_color(dict | None) –Dictionary specifying colors for different geomap features. If None, default colors will be used: `{'land': 'whitesmoke', 'ocean': 'lightblue'}
-
geomap_resolution(('110m', '50m', '10m')) –Resolution of the geomap features. One of '110m', '50m', or '10m'.
-
geometry(bool) –Whether to use the geometry column of the branch components.
Returns:
-
PydeckPlotter–The PydeckPlotter instance with the created layers.
StatisticPlotter
¶
StatisticPlotter(bound_method: Callable, n: Network)
Bases: _StatisticPlotterBase
flowchart TD
pypsa.plot.StatisticPlotter[StatisticPlotter]
pypsa.plot.statistics.plotter._StatisticPlotterBase[_StatisticPlotterBase]
pypsa.plot.statistics.plotter._StatisticPlotterBase --> pypsa.plot.StatisticPlotter
click pypsa.plot.StatisticPlotter href "" "pypsa.plot.StatisticPlotter"
click pypsa.plot.statistics.plotter._StatisticPlotterBase href "" "pypsa.plot.statistics.plotter._StatisticPlotterBase"
Create plots based on output of statistics functions.
Passed arguments and the specified statistics function are stored and called later when the plot is created, depending on the plot type. Also some checks are performed to validated the arguments.
Parameters:
-
bound_method(Callable) –The bound method/ underlying statistic function to call.
-
n(Network) –The network object to use for the statistic calculation.
Methods:
-
__call__–Create simple visualization of the statistic.
-
area–See
chartfor parameters. -
bar–See
chartfor parameters. -
scatter–See
chartfor parameters. -
line–See
chartfor parameters. -
box–See
chartfor parameters. -
violin–See
chartfor parameters. -
histogram–See
chartfor parameters. -
chart–Plot statistics as chart plot.
-
map–Plot statistics on a geographic map.
pypsa.plot.StatisticPlotter.__call__
¶
__call__(kind: str | None = None) -> tuple[Figure, Axes | ndarray, FacetGrid] | tuple[Figure | SubFigure | Any, Axes | Any]
Create simple visualization of the statistic.
This function builds up on any statistics function and allows for a simple
exploration without any further arguments. If a fine grained control is
needed, the plot functions should be used directly (e.g. .plot.bar() instead
of .plot(kind="bar")).
Parameters:
-
kind(str | None, default:None) –Type of chart ("bar", "line", "area", "map"). If None, the default per statistics function, defined in the schema, is used.
Returns:
-
tuple[Figure | SubFigure | Any, Axes | Any]–The figure and axes of the plot.
Examples:
>>> fig, ax, g = n.statistics.installed_capacity.plot(kind="bar")
- Home Overview Release Notes v0.34.0 25th March 2025 Features
pypsa.plot.StatisticPlotter.area
¶
area(**kwargs: Any) -> tuple[Figure, Axes | ndarray, FacetGrid]
See chart for parameters.
- Home Overview Release Notes v0.34.0 25th March 2025 Features
pypsa.plot.StatisticPlotter.bar
¶
bar(**kwargs: Any) -> tuple[Figure, Axes | ndarray, FacetGrid]
See chart for parameters.
- Home Overview Release Notes v0.34.0 25th March 2025 Features
pypsa.plot.StatisticPlotter.scatter
¶
scatter(**kwargs: Any) -> tuple[Figure, Axes | ndarray, FacetGrid]
See chart for parameters.
pypsa.plot.StatisticPlotter.line
¶
line(**kwargs: Any) -> tuple[Figure, Axes | ndarray, FacetGrid]
See chart for parameters.
- Home Overview Release Notes v0.34.0 25th March 2025 Features
pypsa.plot.StatisticPlotter.box
¶
box(**kwargs: Any) -> tuple[Figure, Axes | ndarray, FacetGrid]
See chart for parameters.
pypsa.plot.StatisticPlotter.violin
¶
violin(**kwargs: Any) -> tuple[Figure, Axes | ndarray, FacetGrid]
See chart for parameters.
pypsa.plot.StatisticPlotter.histogram
¶
histogram(**kwargs: Any) -> tuple[Figure, Axes | ndarray, FacetGrid]
See chart for parameters.
pypsa.plot.StatisticPlotter.chart
¶
chart(chart_type: str, x: str | None = None, y: str | None = None, color: str | None = None, facet_col: str | None = None, facet_row: str | None = None, stacked: bool = True, query: str | None = None, nice_names: bool = True, carrier: Sequence[str] | str | None = None, bus_carrier: Sequence[str] | str | None = None, storage: bool | None = None, sharex: bool | None = None, sharey: bool | None = None, height: float | None = None, aspect: float | None = None, row_order: Sequence[str] | None = None, col_order: Sequence[str] | None = None, hue_order: Sequence[str] | None = None, hue_kws: dict[str, Any] | None = None, despine: bool = True, margin_titles: bool = False, xlim: tuple[float, float] | None = None, ylim: tuple[float, float] | None = None, subplot_kws: dict[str, Any] | None = None, gridspec_kws: dict[str, Any] | None = None, **kwargs: Any) -> tuple[Figure, Axes | ndarray, FacetGrid]
Plot statistics as chart plot.
This function builds up on any statistics function and creates a chart plot based on it's output. Seaborn is used to create the plot.
Parameters:
-
x(str, default:None) –Data to show on x-axis. E.g. "carrier". Default depends on underlying statistics function.
-
y(str, default:"value") –Data to show on y-axis. E.g. "value".
-
color(str | None, default:"carrier") –Data to show as color. Pass None to disable color mapping.
-
facet_col(str | None, default:None) –Whether to create subplots with conditional subsets of the data. See
seaborn.objects.Plot.facetfor more information. -
facet_row(str | None, default:None) –Whether to create subplots with conditional subsets of the data. See
seaborn.objects.Plot.facetfor more information. -
stacked(bool, default:False) –Whether to stack the bars. See
seaborn.objects.Stackfor more -
query(str | None, default:None) –Pandas query string to filter the data before plotting. E.g. "value > 0".
-
nice_names(bool, default:True) –Whether to use nice names for components, as defined in
c.static.nice_names. -
carrier(Sequence[str] | str | None, default:None) –Filter by carrier of components. If specified, only considers assets with the given carrier(s). More information can be found in the documentation of the statistics functions.
-
bus_carrier(Sequence[str] | str | None, default:None) –Filter by carrier of connected buses. If specified, only considers assets connected to buses with the given carrier(s). More information can be found in the documentation of the statistics functions.
-
storage(bool | None, default:None) –Whether to include storage components in the statistics. Can only be used when chosen statistics function supports it (e.g.
optimal_capacity,installed_capacity). Default is False for those functions. -
sharex(bool | None, default:None) –Whether to share x axes across all facets. If None, will be True when x is "value".
-
sharey(bool | None, default:None) –Whether to share y axes across all facets. If None, will be True when y is "value".
-
height(float, default:3) –Height (in inches) of each facet.
-
aspect(float, default:2) –Aspect ratio of each facet, so that aspect * height gives the width.
-
row_order(Sequence[str] | None, default:None) –Order to organize the rows of the grid. If None, the order is determined by the data.
-
col_order(Sequence[str] | None, default:None) –Order to organize the columns of the grid. If None, the order is determined by the data.
-
hue_order(Sequence[str] | None, default:None) –Order for the levels of the hue variable. If None, the order is determined by the data.
-
hue_kws(dict[str, Any] | None, default:None) –Other keyword arguments to be passed to the function that maps the hue semantic.
-
despine(bool, default:True) –Remove the top and right spines from the plots.
-
margin_titles(bool, default:False) –Whether to place the row/column titles in the margins, rather than centered over the grid.
-
xlim(tuple[float, float] | None, default:None) –Limits for the x axis. If None, uses the default xlim.
-
ylim(tuple[float, float] | None, default:None) –Limits for the y axis. If None, uses the default ylim.
-
subplot_kws(dict[str, Any] | None, default:None) –Dictionary of keyword arguments for the subplots. Passed to the underlying function.
-
gridspec_kws(dict[str, Any] | None, default:None) –Dictionary of keyword arguments passed to the gridspec module for creating the grid for the figure.
-
**kwargs(Any, default:{}) –Additional keyword arguments for the plot function. These are passed to the seaborn plot object (
seaborn.objects.Plot).
Returns:
-
tuple[Figure, Axes | ndarray, FacetGrid]–The figure, axes and FacetGrid of the plot.
Examples:
>>> fig, ax, g = n.statistics.installed_capacity.plot.bar(x="carrier", y="value", color=None)
pypsa.plot.StatisticPlotter.map
¶
map(ax: Axes | None = None, projection: Any = None, geomap: bool = True, geomap_resolution: Literal['10m', '50m', '110m'] = '50m', geomap_color: dict | bool | None = None, boundaries: tuple[float, float, float, float] | None = None, title: str = '', bus_carrier: str | None = None, carrier: str | None = None, transmission_flow: bool | None = None, bus_area_fraction: float = 0.02, branch_area_fraction: float = 0.02, flow_area_fraction: float = 0.02, draw_legend_circles: bool = True, draw_legend_lines: bool | None = None, draw_legend_arrows: bool | None = None, draw_legend_patches: bool = True, legend_circles_kw: dict | None = None, legend_lines_kw: dict | None = None, legend_arrows_kw: dict | None = None, legend_patches_kw: dict | None = None, bus_split_circle: bool | None = None, storage: bool | None = None, **kwargs: Any) -> tuple[Figure | SubFigure | Any, Axes | Any]
Plot statistics on a geographic map.
This function builds upon any statistics function and creates a geographical visualization based on its output. It uses the MapPlotGenerator to render the network components with sizes and colors based on the statistics results.
Parameters:
-
ax(Axes, default:None) –Axis to plot on. If None, creates a new figure and axis.
-
projection(Projection, default:None) –Map projection to use. If None and geomap is True, uses the network's CRS.
-
geomap(bool, default:True) –Whether to add geographic features with cartopy.
-
geomap_resolution(('10m', '50m', '110m'), default:'10m') –Resolution of geographic features.
-
geomap_color(dict or bool, default:None) –Colors for geographic features. If True, uses defaults. If a dict, keys can include 'ocean', 'land', 'border', 'coastline'.
-
boundaries(tuple(float, float, float, float), default:None) –Plot boundaries as (xmin, xmax, ymin, ymax).
-
title(str, default:"") –Plot title.
-
bus_carrier(str, default:None) –Filter by carrier of connected buses.
-
carrier(str, default:None) –Filter by carrier of components.
-
transmission_flow(bool, default:None) –Whether to plot transmission flows. If True, draws flow arrows instead of lines.
-
bus_area_fraction(float, default:0.02) –Fraction of plot area to be covered by bus circles.
-
branch_area_fraction(float, default:0.02) –Fraction of plot area to be covered by branch lines.
-
flow_area_fraction(float, default:0.02) –Fraction of plot area to be covered by flow arrows.
-
draw_legend_circles(bool, default:True) –Whether to draw a legend for bus sizes.
-
draw_legend_lines(bool, default:None) –Whether to draw a legend for line widths. Only valid when transmission_flow is False.
-
draw_legend_arrows(bool, default:None) –Whether to draw a legend for flow arrows. Only valid when transmission_flow is True.
-
draw_legend_patches(bool, default:True) –Whether to draw a legend for carrier colors.
-
legend_circles_kw(dict, default:None) –Additional keyword arguments for the circles legend.
-
legend_lines_kw(dict, default:None) –Additional keyword arguments for the lines legend.
-
legend_arrows_kw(dict, default:None) –Additional keyword arguments for the arrows legend.
-
legend_patches_kw(dict, default:None) –Additional keyword arguments for the patches legend.
-
bus_split_circle(bool, default:None) –Whether to draw half circles for positive/negative values.
-
storage(bool, default:None) –Whether to show storage capacity in capacity plots. Only valid when chosen statistics function supports it (e.g.
optimal_capacity,installed_capacity). -
**kwargs(Any, default:{}) –Additional keyword arguments passed to the MapPlotGenerator.draw_map method.
Returns:
-
tuple(Figure, Axes)–The figure and axes of the plot.
Examples:
>>> fig, ax = n.statistics.installed_capacity.plot.map(geomap=True, title="Installed Capacity")
- Home Overview Release Notes v0.34.0 25th March 2025 Features
StatisticInteractivePlotter
¶
StatisticInteractivePlotter(bound_method: Callable, n: Network)
Bases: _StatisticPlotterBase
flowchart TD
pypsa.plot.StatisticInteractivePlotter[StatisticInteractivePlotter]
pypsa.plot.statistics.plotter._StatisticPlotterBase[_StatisticPlotterBase]
pypsa.plot.statistics.plotter._StatisticPlotterBase --> pypsa.plot.StatisticInteractivePlotter
click pypsa.plot.StatisticInteractivePlotter href "" "pypsa.plot.StatisticInteractivePlotter"
click pypsa.plot.statistics.plotter._StatisticPlotterBase href "" "pypsa.plot.statistics.plotter._StatisticPlotterBase"
Create interactive plots based on output of statistics functions.
Passed arguments and the specified statistics function are stored and called later when the plot is created, depending on the plot type. Also some checks are performed to validate the arguments.
Parameters:
-
bound_method(Callable) –The bound method/ underlying statistic function to call.
-
n(Network) –The network object to use for the statistic calculation.
Methods:
-
__call__–Create simple visualization of the statistic.
-
area–See
chartfor parameters. -
bar–See
chartfor parameters. -
scatter–See
chartfor parameters. -
line–See
chartfor parameters. -
box–See
chartfor parameters. -
violin–See
chartfor parameters. -
histogram–See
chartfor parameters. -
chart–Plot statistics as interactive chart.
pypsa.plot.StatisticInteractivePlotter.__call__
¶
__call__(kind: str | None = None) -> tuple[Figure, Figure | ndarray]
Create simple visualization of the statistic.
This function builds up on any statistics function and allows for a simple
exploration without any further arguments. If a fine grained control is
needed, the plot functions should be used directly (e.g. .plot.bar() instead
of .plot(kind="bar")).
Parameters:
-
kind(str | None, default:None) –Type of chart ("bar", "line", "area"). If None, the default per statistics function, defined in the schema, is used.
Returns:
-
tuple[Figure | SubFigure | Any, Axes | Any]–The figure and axes of the plot.
Examples:
>>> fig = n.statistics.installed_capacity.plot(kind="bar")
pypsa.plot.StatisticInteractivePlotter.area
¶
area(**kwargs: Any) -> Figure
See chart for parameters.
pypsa.plot.StatisticInteractivePlotter.scatter
¶
scatter(**kwargs: Any) -> Figure
See chart for parameters.
pypsa.plot.StatisticInteractivePlotter.line
¶
line(**kwargs: Any) -> Figure
See chart for parameters.
pypsa.plot.StatisticInteractivePlotter.violin
¶
violin(**kwargs: Any) -> Figure
See chart for parameters.
pypsa.plot.StatisticInteractivePlotter.histogram
¶
histogram(**kwargs: Any) -> Figure
See chart for parameters.
pypsa.plot.StatisticInteractivePlotter.chart
¶
chart(chart_type: str, x: str | None = None, y: str | None = None, color: str | None = None, facet_col: str | None = None, facet_row: str | None = None, stacked: bool = True, query: str | None = None, nice_names: bool = True, carrier: Sequence[str] | str | None = None, bus_carrier: Sequence[str] | str | None = None, storage: bool | None = None, sharex: bool | None = None, sharey: bool | None = None, height: int = 500, width: int = 800, row_order: Sequence[str] | None = None, col_order: Sequence[str] | None = None, color_order: Sequence[str] | None = None, color_discrete_map: dict[str, str] | None = None, range_x: list[float] | None = None, range_y: list[float] | None = None, labels: dict[str, str] | None = None, title: str | None = None, **kwargs: Any) -> Figure
Plot statistics as interactive chart.
This function builds up on any statistics function and creates an interactive chart plot based on its output. Plotly is used to create the plot.
Parameters:
-
x(str, default:None) –Data to show on x-axis. E.g. "carrier". Default depends on underlying statistics function.
-
y(str, default:"value") –Data to show on y-axis. E.g. "value".
-
color(str | None, default:"carrier") –Data to show as color. Pass None to disable color mapping.
-
facet_col(str | None, default:None) –Whether to create subplots with conditional subsets of the data.
-
facet_row(str | None, default:None) –Whether to create subplots with conditional subsets of the data.
-
stacked(bool, default:False) –Whether to stack the bars or areas.
-
query(str | None, default:None) –Pandas query string to filter the data before plotting. E.g. "value > 0".
-
nice_names(bool, default:True) –Whether to use nice names for components, as defined in
c.static.nice_names. -
carrier(Sequence[str] | str | None, default:None) –Filter by carrier of components. If specified, only considers assets with the given carrier(s). More information can be found in the documentation of the statistics functions.
-
bus_carrier(Sequence[str] | str | None, default:None) –Filter by carrier of connected buses. If specified, only considers assets connected to buses with the given carrier(s). More information can be found in the documentation of the statistics functions.
-
storage(bool | None, default:None) –Whether to include storage components in the statistics. Can only be used when chosen statistics function supports it (e.g.
optimal_capacity,installed_capacity). Default is False for those functions. -
sharex(bool | None, default:None) –Whether to share x axes across all facets. If None, will be True when x is "value".
-
sharey(bool | None, default:None) –Whether to share y axes across all facets. If None, will be True when y is "value".
-
height(int, default:500) –Height of the plot in pixels.
-
width(int, default:800) –Width of the plot in pixels.
-
row_order(Sequence[str] | None, default:None) –Order to organize the rows of the grid. If None, the order is determined by the data.
-
col_order(Sequence[str] | None, default:None) –Order to organize the columns of the grid. If None, the order is determined by the data.
-
color_order(Sequence[str] | None, default:None) –Order for the levels of the color variable. If None, the order is determined by the data.
-
color_discrete_map(dict[str, str] | None, default:None) –Mapping from discrete values to colors. If None, uses the default carrier colors.
-
range_x(list[float] | None, default:None) –Limits for the x axis. If None, uses the default x range.
-
range_y(list[float] | None, default:None) –Limits for the y axis. If None, uses the default y range.
-
labels(dict[str, str] | None, default:None) –Dictionary of axis labels to override the default labels.
-
title(str | None, default:None) –Title of the plot. If None, uses the statistics function name.
-
**kwargs(Any, default:{}) –Additional keyword arguments for the plot function. These are passed to the Plotly Express function.
Returns:
-
Figure–The interactive Plotly figure.
Examples:
>>> fig = n.statistics.installed_capacity.iplot.bar(x="carrier", y="value", color="carrier")
-
API Reference
Networks
Network
Plotting
StatisticInteractivePlotter