pytrnsys_process.plot package#

Submodules#

pytrnsys_process.plot.plot_wrappers module#

Plotting wrappers to provide a simplified interface to the User, while allow development of reusable OOP structures.

Note

Many of these plotting routines do not add labels and legends. This should be done using the figure and axis handles afterwards.

pytrnsys_process.plot.plot_wrappers.line_plot(df: DataFrame, columns: list[str], use_legend: bool = True, size: tuple[float, float] = (7.8, 3.9), **kwargs: Any) tuple[Figure, Axes][source]#

Create a line plot using the provided DataFrame columns.

Parameters:
  • df (pandas.DataFrame) – the dataframe to plot

  • columns (list of str) – names of columns to plot

  • use_legend (bool, default 'True') – whether to show the legend or not

  • size (tuple of (float, float)) – size of the figure (width, height)

  • **kwargs – Additional keyword arguments are documented in pandas.DataFrame.plot().

Return type:

tuple of (matplotlib.figure.Figure, matplotlib.axes.Axes)

Examples

>>> api.line_plot(simulation.hourly, ["QSrc1TIn", "QSrc1TOut"])
../_images/pytrnsys_process-plot-1.png
pytrnsys_process.plot.plot_wrappers.bar_chart(df: DataFrame, columns: list[str], use_legend: bool = True, size: tuple[float, float] = (7.8, 3.9), **kwargs: Any) tuple[Figure, Axes][source]#

Create a bar chart with multiple columns displayed as grouped bars. The **kwargs are currently not passed on.

Parameters:
Return type:

tuple of (matplotlib.figure.Figure, matplotlib.axes.Axes)

Examples

>>> api.bar_chart(simulation.monthly, ["QSnk60P","QSnk60PauxCondSwitch_kW"])
../_images/pytrnsys_process-plot-2.png
pytrnsys_process.plot.plot_wrappers.stacked_bar_chart(df: DataFrame, columns: list[str], use_legend: bool = True, size: tuple[float, float] = (7.8, 3.9), **kwargs: Any) tuple[Figure, Axes][source]#

Bar chart with stacked bars

Parameters:
Return type:

tuple of (matplotlib.figure.Figure, matplotlib.axes.Axes)

Examples

>>> api.stacked_bar_chart(simulation.monthly, ["QSnk60P","QSnk60PauxCondSwitch_kW"])
../_images/pytrnsys_process-plot-3.png
pytrnsys_process.plot.plot_wrappers.histogram(df: DataFrame, columns: list[str], use_legend: bool = True, size: tuple[float, float] = (7.8, 3.9), bins: int = 50, **kwargs: Any) tuple[Figure, Axes][source]#

Create a histogram from the given DataFrame columns.

Parameters:
  • df (pandas.DataFrame) – the dataframe to plot

  • columns (list of str) – names of columns to plot

  • use_legend (bool, default 'True') – whether to show the legend or not

  • size (tuple of (float, float)) – size of the figure (width, height)

  • bins (int) – number of histogram bins to be used

  • **kwargs – Additional keyword arguments to pass on to pandas.DataFrame.plot().

Return type:

tuple of (matplotlib.figure.Figure, matplotlib.axes.Axes)

Examples

>>> api.histogram(simulation.hourly, ["QSrc1TIn"], ylabel="")
../_images/pytrnsys_process-plot-4.png
pytrnsys_process.plot.plot_wrappers.energy_balance(df: DataFrame, q_in_columns: list[str], q_out_columns: list[str], q_imb_column: str | None = None, use_legend: bool = True, size: tuple[float, float] = (7.8, 3.9), **kwargs: Any) tuple[Figure, Axes][source]#

Create a stacked bar chart showing energy balance with inputs, outputs and imbalance. This function creates an energy balance visualization where:

  • Input energies are shown as positive values

  • Output energies are shown as negative values

  • Energy imbalance is either provided or calculated as (sum of inputs + sum of outputs)

Parameters:
  • df (pandas.DataFrame) – the dataframe to plot

  • q_in_columns (list of str) – column names representing energy inputs

  • q_out_columns (list of str) – column names representing energy outputs

  • q_imb_column (list of str, optional) – column name containing pre-calculated energy imbalance

  • use_legend (bool, default 'True') – whether to show the legend or not

  • size (tuple of (float, float)) – size of the figure (width, height)

  • **kwargs – Additional keyword arguments to pass on to pandas.DataFrame.plot().

Return type:

tuple of (matplotlib.figure.Figure, matplotlib.axes.Axes)

Examples

>>> api.energy_balance(
>>> simulation.monthly,
>>> q_in_columns=["QSnk60PauxCondSwitch_kW"],
>>> q_out_columns=["QSnk60P", "QSnk60dQlossTess", "QSnk60dQ"],
>>> q_imb_column="QSnk60qImbTess",
>>> xlabel=""
>>> )
../_images/pytrnsys_process-plot-5.png
pytrnsys_process.plot.plot_wrappers.energy_balance_with_lines(df: DataFrame, q_in_columns: list[str], q_out_columns: list[str], line_columns: list[str] | None = None, q_imb_column: str | None = None, use_legend: bool = True, size: tuple[float, float] = (7.8, 3.9), **kwargs: Any) tuple[Figure, Axes, Axes][source]#

Create a stacked bar chart showing energy balance with inputs, outputs and imbalance. On top of which one or more lines will be plotted.

This function creates an energy balance visualization where:

  • Input energies are shown as positive values

  • Output energies are shown as negative values

  • Energy imbalance is either provided or calculated as (sum of inputs + sum of outputs)

Parameters:
  • df (pandas.DataFrame) – the dataframe to plot

  • q_in_columns (list of str) – column names representing energy inputs

  • q_out_columns (list of str) – column names representing energy outputs

  • q_imb_column (list of str, optional) – column name containing pre-calculated energy imbalance

  • line_columns (list of str) – column names that should be plotted as line on top of the energy balance.

  • use_legend (bool, default 'True') – whether to show the legend or not

  • size (tuple of (float, float)) – size of the figure (width, height)

  • energy_balance_ylabel (str) – y-axis label for the energy balance.

  • line_ylabel (str) – y-axis label for the lines.

  • **kwargs – Additional keyword arguments to pass on to pandas.DataFrame.plot().

Return type:

tuple of (matplotlib.figure.Figure, matplotlib.axes.Axes)

Examples

>>> api.energy_balance_with_lines(
>>> simulation.monthly,
>>> q_in_columns=["QSnk60PauxCondSwitch_kW"],
>>> q_out_columns=["QSnk60P", "QSnk60dQlossTess", "QSnk60dQ"],
>>> q_imb_column="QSnk60qImbTess",
>>> xlabel=""
>>> )
../_images/pytrnsys_process-plot-6.png
pytrnsys_process.plot.plot_wrappers.scatter_plot(df: DataFrame, x_column: str, y_column: str, use_legend: bool = True, size: tuple[float, float] = (7.8, 3.9), **kwargs: Any) tuple[Figure, Axes][source]#

Create a scatter plot to show numerical relationships between x and y variables.

Parameters:
  • df (pandas.DataFrame) – the dataframe to plot

  • x_column (str) – coloumn name for x-axis values

  • y_column (str) – coloumn name for y-axis values

use_legend: bool, default ‘True’

whether to show the legend or not

size: tuple of (float, float)

size of the figure (width, height)

**kwargs :

Additional keyword arguments to pass on to pandas.DataFrame.plot.scatter().

Return type:

tuple of (matplotlib.figure.Figure, matplotlib.axes.Axes)

Examples

Simple scatter plot

>>> api.scatter_plot(
...     simulation.monthly, x_column="QSnk60dQlossTess", y_column="QSnk60dQ"
... )
../_images/pytrnsys_process-plot-7.png
pytrnsys_process.plot.plot_wrappers.scalar_compare_plot(df: DataFrame, x_column: str, y_column: str, group_by_color: str | None = None, group_by_marker: str | None = None, use_legend: bool = True, size: tuple[float, float] = (7.8, 3.9), scatter_kwargs: dict[str, Any] | None = None, line_kwargs: dict[str, Any] | None = None, **kwargs: Any) tuple[Figure, Axes][source]#

Create a scalar comparison plot with up to two grouping variables. This visualization allows simultaneous analysis of:

  • Numerical relationships between x and y variables

  • Categorical grouping through color encoding

  • Secondary categorical grouping through marker styles

Note

To change the figure properties a separation is included. scatter_kwargs are used to change the markers. line_kwargs are used to change the lines.

See: - markers: https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.scatter.html - lines: https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.plot.html

Parameters:
  • df (pandas.DataFrame) – the dataframe to plot

  • x_column (str) – column name for x-axis values

  • y_column (str) – column name for y-axis values

  • group_by_color (str, optional) – column name for color grouping

  • group_by_marker (str, optional) – column name for marker style grouping

  • use_legend (bool, default 'True') – whether to show the legend or not

  • size (tuple of (float, float)) – size of the figure (width, height)

  • line_kwargs – Additional keyword arguments to pass on to matplotlib.axes.Axes.plot().

  • scatter_kwargs – Additional keyword arguments to pass on to matplotlib.axes.Axes.scatter().

  • **kwargs – Should never be used! Use ‘line_kwargs’ or ‘scatter_kwargs’ instead.

Return type:

tuple of (matplotlib.figure.Figure, matplotlib.axes.Axes)

Examples

Compare plot

>>> api.scalar_compare_plot(
...     comparison_data,
...     x_column="VIceSscaled",
...     y_column="VIceRatioMax",
...     group_by_color="yearly_demand_GWh",
...     group_by_marker="ratioDHWtoSH_allSinks",
... )
../_images/pytrnsys_process-plot-8.png
pytrnsys_process.plot.plot_wrappers.get_figure_with_twin_x_axis() tuple[Figure, Axes, Axes][source]#

Used to make figures with different y axes on the left and right. To create such a figure, pass the lax to one plotting method and pass the rax to another.

Warning

Be careful when combining plots. MatPlotLib will not complain when you provide incompatible x-axes. An example: combining a time-series with dates with a histogram with temperatures. In this case, the histogram will disappear without any feedback.

Note

The legend of a twin_x plot is a special case: To have all entries into a single plot, use fig.legend https://matplotlib.org/stable/api/_as_gen/matplotlib.figure.Figure.legend.html

To instead have two separate legends, one for each y-axis, use lax.legend and rax.legend. https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.legend.html

Returns:

  • fig – Figure object

  • lax – Axis object for the data on the left y-axis.

  • rax – Axis object for the data on the right y-axis.

Examples

Twin axis plot with a single legend

>>> fig, lax, rax = api.get_figure_with_twin_x_axis()
>>> api.line_plot(simulation.monthly, ["QSnk60P",], ylabel="Power [kWh]", use_legend=False, fig=fig, ax=lax)
>>> api.line_plot(simulation.monthly, ["QSnk60qImbTess", "QSnk60dQlossTess", "QSnk60dQ"], marker="*",
...     ylabel="Fluxes [kWh]", use_legend=False, fig=fig, ax=rax)
>>> fig.legend(loc="center", bbox_to_anchor=(0.6, 0.7))
../_images/pytrnsys_process-plot-9.png

Twin axis plot with two legends

>>> fig, lax, rax = api.get_figure_with_twin_x_axis()
>>> api.line_plot(simulation.monthly, ["QSnk60P",], ylabel="Power [kWh]", use_legend=False, fig=fig, ax=lax)
>>> api.line_plot(simulation.monthly, ["QSnk60qImbTess", "QSnk60dQlossTess", "QSnk60dQ"], marker="*",
...     ylabel="Fluxes [kWh]", use_legend=False, fig=fig, ax=rax)
>>> lax.legend(loc="center left")
>>> rax.legend(loc="center right")
../_images/pytrnsys_process-plot-10.png
exception pytrnsys_process.plot.plot_wrappers.ColumnNotFoundError[source]#

Bases: Exception

This exception is raised when given column names are not available in the dataframe

pytrnsys_process.plot.plotters module#

pytrnsys_process.plot.plotters.plot_settings = Plot(file_formats=['.png', '.pdf', '.emf'], figure_sizes={'A4': (7.8, 3.9), 'A4_HALF': (3.8, 3.9)}, inkscape_path='C://Program Files//Inkscape//bin//inkscape.exe', date_format='%b %Y', label_font_size=10, legend_font_size=8, title_font_size=12, markers=['x', 'o', '^', 'D', 'v', '<', '>', 'p', '*', 's'])#

Settings shared by all plots

class pytrnsys_process.plot.plotters.ChartBase[source]#

Bases: object

cmap: str | None = None#
plot(df: DataFrame, columns: list[str], **kwargs) tuple[Figure, Axes][source]#
check_for_cmap(kwargs, plot_kwargs)[source]#
get_cmap(kwargs) str | None[source]#
static get_fig_and_ax(kwargs, size)[source]#
get_fig_and_multi_ax(kwargs, size)[source]#
static prep_subplots_for_legend_outside_of_plot(size) tuple[Figure, Axes, Axes][source]#
class pytrnsys_process.plot.plotters.StackedBarChart[source]#

Bases: ChartBase

cmap: str | None = 'inferno_r'#
class pytrnsys_process.plot.plotters.EnergyBalanceChart[source]#

Bases: ChartBase

cmap: str | None = 'inferno_r'#
plot(df: DataFrame, columns: dict[Any, Any], **kwargs) tuple[Figure, Axes, Axes][source]#
class pytrnsys_process.plot.plotters.BarChart[source]#

Bases: ChartBase

cmap: str | None = None#
class pytrnsys_process.plot.plotters.LinePlot[source]#

Bases: ChartBase

cmap: str | None = None#
class pytrnsys_process.plot.plotters.Histogram(bins: int = 50)[source]#

Bases: ChartBase

bins: int = 50#
__init__(bins: int = 50) None#
class pytrnsys_process.plot.plotters.ScatterPlot[source]#

Bases: ChartBase

cmap: str | None = 'Paired'#
class pytrnsys_process.plot.plotters.ScalarComparePlot[source]#

Bases: ChartBase

Handles comparative scatter plots with dual grouping by color and markers.

cmap: str | None = 'Paired'#
pytrnsys_process.plot.plotters.get_date_time_axis_locator_and_formatter(data_frequency: Literal['step', 'hourly', 'monthly']) Tuple[AutoDateLocator, ConciseDateFormatter][source]#

Method to prepare an axis locator and a date time formattter to adjust the date time formatting. Can be used as follows: ax.xaxis.set_major_formatter(formatter) ax.xaxis.set_major_locator(date_locator)

Parameters:

data_frequency (str) – Size of the timestep. This can be ‘step’, ‘hourly’, and ‘monthly’.

pytrnsys_process.plot.plotters.get_frequency_of_data(df: DataFrame) Literal['step', 'hourly', 'monthly'][source]#

Method to identify the timestep size of the give dataframe. Can return ‘step’, ‘hourly’, and ‘monthly’.

pytrnsys_process.plot.plotters.format_date_time_twin_axis(lax: Axes, rax: Axes, data_frequency: Literal['step', 'hourly', 'monthly'])[source]#

Method to update dateTime formatting for twin axes.

Parameters:
  • lax (_plt.Axes) – left-axis handle

  • rax (_plt.Axes) – right-axis handle

  • data_frequency (str) – Size of the timestep. This can be ‘step’, ‘hourly’, and ‘monthly’.

Module contents#

pytrnsys_process.plot.line_plot(df: DataFrame, columns: list[str], use_legend: bool = True, size: tuple[float, float] = (7.8, 3.9), **kwargs: Any) tuple[Figure, Axes][source]#

Create a line plot using the provided DataFrame columns.

Parameters:
  • df (pandas.DataFrame) – the dataframe to plot

  • columns (list of str) – names of columns to plot

  • use_legend (bool, default 'True') – whether to show the legend or not

  • size (tuple of (float, float)) – size of the figure (width, height)

  • **kwargs – Additional keyword arguments are documented in pandas.DataFrame.plot().

Return type:

tuple of (matplotlib.figure.Figure, matplotlib.axes.Axes)

Examples

>>> api.line_plot(simulation.hourly, ["QSrc1TIn", "QSrc1TOut"])
../_images/pytrnsys_process-plot-11.png
pytrnsys_process.plot.bar_chart(df: DataFrame, columns: list[str], use_legend: bool = True, size: tuple[float, float] = (7.8, 3.9), **kwargs: Any) tuple[Figure, Axes][source]#

Create a bar chart with multiple columns displayed as grouped bars. The **kwargs are currently not passed on.

Parameters:
Return type:

tuple of (matplotlib.figure.Figure, matplotlib.axes.Axes)

Examples

>>> api.bar_chart(simulation.monthly, ["QSnk60P","QSnk60PauxCondSwitch_kW"])
../_images/pytrnsys_process-plot-12.png
pytrnsys_process.plot.stacked_bar_chart(df: DataFrame, columns: list[str], use_legend: bool = True, size: tuple[float, float] = (7.8, 3.9), **kwargs: Any) tuple[Figure, Axes][source]#

Bar chart with stacked bars

Parameters:
Return type:

tuple of (matplotlib.figure.Figure, matplotlib.axes.Axes)

Examples

>>> api.stacked_bar_chart(simulation.monthly, ["QSnk60P","QSnk60PauxCondSwitch_kW"])
../_images/pytrnsys_process-plot-13.png
pytrnsys_process.plot.histogram(df: DataFrame, columns: list[str], use_legend: bool = True, size: tuple[float, float] = (7.8, 3.9), bins: int = 50, **kwargs: Any) tuple[Figure, Axes][source]#

Create a histogram from the given DataFrame columns.

Parameters:
  • df (pandas.DataFrame) – the dataframe to plot

  • columns (list of str) – names of columns to plot

  • use_legend (bool, default 'True') – whether to show the legend or not

  • size (tuple of (float, float)) – size of the figure (width, height)

  • bins (int) – number of histogram bins to be used

  • **kwargs – Additional keyword arguments to pass on to pandas.DataFrame.plot().

Return type:

tuple of (matplotlib.figure.Figure, matplotlib.axes.Axes)

Examples

>>> api.histogram(simulation.hourly, ["QSrc1TIn"], ylabel="")
../_images/pytrnsys_process-plot-14.png
pytrnsys_process.plot.energy_balance(df: DataFrame, q_in_columns: list[str], q_out_columns: list[str], q_imb_column: str | None = None, use_legend: bool = True, size: tuple[float, float] = (7.8, 3.9), **kwargs: Any) tuple[Figure, Axes][source]#

Create a stacked bar chart showing energy balance with inputs, outputs and imbalance. This function creates an energy balance visualization where:

  • Input energies are shown as positive values

  • Output energies are shown as negative values

  • Energy imbalance is either provided or calculated as (sum of inputs + sum of outputs)

Parameters:
  • df (pandas.DataFrame) – the dataframe to plot

  • q_in_columns (list of str) – column names representing energy inputs

  • q_out_columns (list of str) – column names representing energy outputs

  • q_imb_column (list of str, optional) – column name containing pre-calculated energy imbalance

  • use_legend (bool, default 'True') – whether to show the legend or not

  • size (tuple of (float, float)) – size of the figure (width, height)

  • **kwargs – Additional keyword arguments to pass on to pandas.DataFrame.plot().

Return type:

tuple of (matplotlib.figure.Figure, matplotlib.axes.Axes)

Examples

>>> api.energy_balance(
>>> simulation.monthly,
>>> q_in_columns=["QSnk60PauxCondSwitch_kW"],
>>> q_out_columns=["QSnk60P", "QSnk60dQlossTess", "QSnk60dQ"],
>>> q_imb_column="QSnk60qImbTess",
>>> xlabel=""
>>> )
../_images/pytrnsys_process-plot-15.png
pytrnsys_process.plot.energy_balance_with_lines(df: DataFrame, q_in_columns: list[str], q_out_columns: list[str], line_columns: list[str] | None = None, q_imb_column: str | None = None, use_legend: bool = True, size: tuple[float, float] = (7.8, 3.9), **kwargs: Any) tuple[Figure, Axes, Axes][source]#

Create a stacked bar chart showing energy balance with inputs, outputs and imbalance. On top of which one or more lines will be plotted.

This function creates an energy balance visualization where:

  • Input energies are shown as positive values

  • Output energies are shown as negative values

  • Energy imbalance is either provided or calculated as (sum of inputs + sum of outputs)

Parameters:
  • df (pandas.DataFrame) – the dataframe to plot

  • q_in_columns (list of str) – column names representing energy inputs

  • q_out_columns (list of str) – column names representing energy outputs

  • q_imb_column (list of str, optional) – column name containing pre-calculated energy imbalance

  • line_columns (list of str) – column names that should be plotted as line on top of the energy balance.

  • use_legend (bool, default 'True') – whether to show the legend or not

  • size (tuple of (float, float)) – size of the figure (width, height)

  • energy_balance_ylabel (str) – y-axis label for the energy balance.

  • line_ylabel (str) – y-axis label for the lines.

  • **kwargs – Additional keyword arguments to pass on to pandas.DataFrame.plot().

Return type:

tuple of (matplotlib.figure.Figure, matplotlib.axes.Axes)

Examples

>>> api.energy_balance_with_lines(
>>> simulation.monthly,
>>> q_in_columns=["QSnk60PauxCondSwitch_kW"],
>>> q_out_columns=["QSnk60P", "QSnk60dQlossTess", "QSnk60dQ"],
>>> q_imb_column="QSnk60qImbTess",
>>> xlabel=""
>>> )
../_images/pytrnsys_process-plot-16.png
pytrnsys_process.plot.scatter_plot(df: DataFrame, x_column: str, y_column: str, use_legend: bool = True, size: tuple[float, float] = (7.8, 3.9), **kwargs: Any) tuple[Figure, Axes][source]#

Create a scatter plot to show numerical relationships between x and y variables.

Parameters:
  • df (pandas.DataFrame) – the dataframe to plot

  • x_column (str) – coloumn name for x-axis values

  • y_column (str) – coloumn name for y-axis values

use_legend: bool, default ‘True’

whether to show the legend or not

size: tuple of (float, float)

size of the figure (width, height)

**kwargs :

Additional keyword arguments to pass on to pandas.DataFrame.plot.scatter().

Return type:

tuple of (matplotlib.figure.Figure, matplotlib.axes.Axes)

Examples

Simple scatter plot

>>> api.scatter_plot(
...     simulation.monthly, x_column="QSnk60dQlossTess", y_column="QSnk60dQ"
... )
../_images/pytrnsys_process-plot-17.png
pytrnsys_process.plot.scalar_compare_plot(df: DataFrame, x_column: str, y_column: str, group_by_color: str | None = None, group_by_marker: str | None = None, use_legend: bool = True, size: tuple[float, float] = (7.8, 3.9), scatter_kwargs: dict[str, Any] | None = None, line_kwargs: dict[str, Any] | None = None, **kwargs: Any) tuple[Figure, Axes][source]#

Create a scalar comparison plot with up to two grouping variables. This visualization allows simultaneous analysis of:

  • Numerical relationships between x and y variables

  • Categorical grouping through color encoding

  • Secondary categorical grouping through marker styles

Note

To change the figure properties a separation is included. scatter_kwargs are used to change the markers. line_kwargs are used to change the lines.

See: - markers: https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.scatter.html - lines: https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.plot.html

Parameters:
  • df (pandas.DataFrame) – the dataframe to plot

  • x_column (str) – column name for x-axis values

  • y_column (str) – column name for y-axis values

  • group_by_color (str, optional) – column name for color grouping

  • group_by_marker (str, optional) – column name for marker style grouping

  • use_legend (bool, default 'True') – whether to show the legend or not

  • size (tuple of (float, float)) – size of the figure (width, height)

  • line_kwargs – Additional keyword arguments to pass on to matplotlib.axes.Axes.plot().

  • scatter_kwargs – Additional keyword arguments to pass on to matplotlib.axes.Axes.scatter().

  • **kwargs – Should never be used! Use ‘line_kwargs’ or ‘scatter_kwargs’ instead.

Return type:

tuple of (matplotlib.figure.Figure, matplotlib.axes.Axes)

Examples

Compare plot

>>> api.scalar_compare_plot(
...     comparison_data,
...     x_column="VIceSscaled",
...     y_column="VIceRatioMax",
...     group_by_color="yearly_demand_GWh",
...     group_by_marker="ratioDHWtoSH_allSinks",
... )
../_images/pytrnsys_process-plot-18.png
pytrnsys_process.plot.get_figure_with_twin_x_axis() tuple[Figure, Axes, Axes][source]#

Used to make figures with different y axes on the left and right. To create such a figure, pass the lax to one plotting method and pass the rax to another.

Warning

Be careful when combining plots. MatPlotLib will not complain when you provide incompatible x-axes. An example: combining a time-series with dates with a histogram with temperatures. In this case, the histogram will disappear without any feedback.

Note

The legend of a twin_x plot is a special case: To have all entries into a single plot, use fig.legend https://matplotlib.org/stable/api/_as_gen/matplotlib.figure.Figure.legend.html

To instead have two separate legends, one for each y-axis, use lax.legend and rax.legend. https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.legend.html

Returns:

  • fig – Figure object

  • lax – Axis object for the data on the left y-axis.

  • rax – Axis object for the data on the right y-axis.

Examples

Twin axis plot with a single legend

>>> fig, lax, rax = api.get_figure_with_twin_x_axis()
>>> api.line_plot(simulation.monthly, ["QSnk60P",], ylabel="Power [kWh]", use_legend=False, fig=fig, ax=lax)
>>> api.line_plot(simulation.monthly, ["QSnk60qImbTess", "QSnk60dQlossTess", "QSnk60dQ"], marker="*",
...     ylabel="Fluxes [kWh]", use_legend=False, fig=fig, ax=rax)
>>> fig.legend(loc="center", bbox_to_anchor=(0.6, 0.7))
../_images/pytrnsys_process-plot-19.png

Twin axis plot with two legends

>>> fig, lax, rax = api.get_figure_with_twin_x_axis()
>>> api.line_plot(simulation.monthly, ["QSnk60P",], ylabel="Power [kWh]", use_legend=False, fig=fig, ax=lax)
>>> api.line_plot(simulation.monthly, ["QSnk60qImbTess", "QSnk60dQlossTess", "QSnk60dQ"], marker="*",
...     ylabel="Fluxes [kWh]", use_legend=False, fig=fig, ax=rax)
>>> lax.legend(loc="center left")
>>> rax.legend(loc="center right")
../_images/pytrnsys_process-plot-20.png
pytrnsys_process.plot.get_date_time_axis_locator_and_formatter(data_frequency: Literal['step', 'hourly', 'monthly']) Tuple[AutoDateLocator, ConciseDateFormatter][source]#

Method to prepare an axis locator and a date time formattter to adjust the date time formatting. Can be used as follows: ax.xaxis.set_major_formatter(formatter) ax.xaxis.set_major_locator(date_locator)

Parameters:

data_frequency (str) – Size of the timestep. This can be ‘step’, ‘hourly’, and ‘monthly’.

pytrnsys_process.plot.get_frequency_of_data(df: DataFrame) Literal['step', 'hourly', 'monthly'][source]#

Method to identify the timestep size of the give dataframe. Can return ‘step’, ‘hourly’, and ‘monthly’.

pytrnsys_process.plot.format_date_time_twin_axis(lax: Axes, rax: Axes, data_frequency: Literal['step', 'hourly', 'monthly'])[source]#

Method to update dateTime formatting for twin axes.

Parameters:
  • lax (_plt.Axes) – left-axis handle

  • rax (_plt.Axes) – right-axis handle

  • data_frequency (str) – Size of the timestep. This can be ‘step’, ‘hourly’, and ‘monthly’.