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)
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")
pypsa.plot.StatisticPlotter.area
ΒΆ
area(
**kwargs: Any,
) -> tuple[Figure, Axes | ndarray, FacetGrid]
See chart for parameters.
pypsa.plot.StatisticPlotter.bar
ΒΆ
bar(
**kwargs: Any,
) -> tuple[Figure, Axes | ndarray, FacetGrid]
See chart for parameters.
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.
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:
>>> import pypsa
>>> n = pypsa.examples.ac_dc_meshed()
>>> 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:
>>> import pypsa
>>> n = pypsa.examples.ac_dc_meshed()
>>> fig, ax = n.statistics.installed_capacity.plot.map(geomap=True, title="Installed Capacity")
StatisticInteractivePlotter
ΒΆ
StatisticInteractivePlotter(
bound_method: Callable, n: Network
)
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.bar
ΒΆ
bar(**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.box
ΒΆ
box(**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:
>>> import pypsa
>>> n = pypsa.examples.ac_dc_meshed()
>>> fig = n.statistics.installed_capacity.iplot.bar(x="carrier", y="value", color="carrier")