plot
Modules
align_y_axes module
Functions for calculating and aligning y-axis ticks in plots.
Mathematical Formulation:
Tick Spacing Calculation: For a data range \([y_{min}, y_{max}]\) and desired number of ticks \(n\):
\[\Delta y = \frac{y_{max} - y_{min}}{n-1}\]The tick spacing is rounded to a “nice” number:
\[\Delta y_{nice} = \lceil \frac{\Delta y}{10^m} \rceil \cdot 10^m\]where: - \(m = \lfloor \log_{10}(\Delta y) \rfloor\) is the order of magnitude
Zero-Aligned Ticks: When aligning with zero at index \(i\):
\[\begin{split}\begin{align} n_{below} &= i \\ n_{above} &= n - i - 1 \\ y_{min} &= -n_{below} \cdot \Delta y_{nice} \\ y_{max} &= n_{above} \cdot \Delta y_{nice} \end{align}\end{split}\]Y-Axis Alignment: For multiple axes with ranges \([y_{i,min}, y_{i,max}]\):
\[y_{i,offset} = \frac{(y_{i,max} - y_{i,min}) \cdot y_{ref,offset}}{y_{ref,max} - y_{ref,min} + 2y_{ref,offset}} \cdot \frac{1}{1 - \frac{2y_{ref,offset}}{y_{ref,max} - y_{ref,min} + 2y_{ref,offset}}}\]where: - \(y_{ref,offset}\) is the reference axis offset - \(y_{ref,min}, y_{ref,max}\) are the reference axis limits
plot module
Plotting functions and formatting utilities for data visualization.
Mathematical Formulation:
Time Series Plotting: For a time series \(y(t)\):
\[\begin{split}y_{formatted}(t) = \begin{cases} y(t) & \text{if } y_{min} \leq y(t) \leq y_{max} \\ y_{min} & \text{if } y(t) < y_{min} \\ y_{max} & \text{if } y(t) > y_{max} \end{cases}\end{split}\]where: - \(y_{min}, y_{max}\) are the y-axis limits - \(t\) is the time index
Multi-Axis Alignment: For multiple y-axes with values \(y_1, y_2, ..., y_n\):
\[y_i' = \frac{y_i - y_{i,min}}{y_{i,max} - y_{i,min}} \cdot (y_{ref,max} - y_{ref,min}) + y_{ref,min}\]where: - \(y_i\) is the original value on axis i - \(y_{i,min}, y_{i,max}\) are the min/max values on axis i - \(y_{ref,min}, y_{ref,max}\) are the reference axis limits
Time Label Formatting: For time \(t\) with evaluation metric \(m\):
\[\begin{split}label(t) = \begin{cases} h(t) & \text{if } m = \text{"H"} \\ d(t) & \text{if } m = \text{"D"} \\ w(t) & \text{if } m = \text{"W"} \\ M(t) & \text{if } m = \text{"M"} \\ Y(t) & \text{if } m = \text{"A"} \end{cases}\end{split}\]where: - \(h(t)\) is the hour format - \(d(t)\) is the day format - \(w(t)\) is the week format - \(M(t)\) is the month format - \(Y(t)\) is the year format
- class Colors[source]
Bases:
object- beis = (0.8, 0.7254901960784313, 0.4549019607843137)
- blue = (0.2980392156862745, 0.4470588235294118, 0.6901960784313725)
- brown = (0.5764705882352941, 0.47058823529411764, 0.3764705882352941)
- colors = [(0.2980392156862745, 0.4470588235294118, 0.6901960784313725), (0.8666666666666667, 0.5176470588235295, 0.3215686274509804), (0.3333333333333333, 0.6588235294117647, 0.40784313725490196), (0.7686274509803922, 0.3058823529411765, 0.3215686274509804), (0.5058823529411764, 0.4470588235294118, 0.7019607843137254), (0.5764705882352941, 0.47058823529411764, 0.3764705882352941), (0.8549019607843137, 0.5450980392156862, 0.7647058823529411), (0.5490196078431373, 0.5490196078431373, 0.5490196078431373), (0.8, 0.7254901960784313, 0.4549019607843137), (0.39215686274509803, 0.7098039215686275, 0.803921568627451)]
- green = (0.3333333333333333, 0.6588235294117647, 0.40784313725490196)
- grey = (0.5490196078431373, 0.5490196078431373, 0.5490196078431373)
- orange = (0.8666666666666667, 0.5176470588235295, 0.3215686274509804)
- pink = (0.8549019607843137, 0.5450980392156862, 0.7647058823529411)
- purple = (0.5058823529411764, 0.4470588235294118, 0.7019607843137254)
- red = (0.7686274509803922, 0.3058823529411765, 0.3215686274509804)
- sky_blue = (0.39215686274509803, 0.7098039215686275, 0.803921568627451)
- class PlotSettings[source]
Bases:
object- left_y = (0.025, 0.5)
- legend_loc = (0.5, 0.93)
- outward = 68
- right_y_first = (0.86, 0.5)
- right_y_second = (0.975, 0.5)
- class property save_folder
str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.
- x = (0.45, 0.05)
- bar_plot_line_format(label, evaluation_metric)[source]
Convert time label to the format of pandas line plot
- get_fig_axes(title_name, n_plots=1, cols=1, K=0.38, size_inches=(8, 4.3), offset=(0.12, 0.18), ax_dim=(0.65, 0.6), y_offset_add_default=0.04)[source]
- plot_component(simulator, components_1axis, components_2axis=None, components_3axis=None, ylabel_1axis=None, ylabel_2axis=None, ylabel_3axis=None, ylim_1axis=None, ylim_2axis=None, ylim_3axis=None, title=None, nticks=11, roundto_1axis=None, roundto_2axis=None, roundto_3axis=None, yoffset_1axis=None, yoffset_2axis=None, yoffset_3axis=None, align_zero=True, show=False)[source]
General plot function for components.
- Parameters:
simulator – The simulator object containing the model and time steps.
components_1axis (list) – List of tuples (component_id, attribute) for the first y-axis.
components_2axis (list, optional) – List of tuples for the second y-axis.
components_3axis (list, optional) – List of tuples for the third y-axis.
show (bool) – Whether to display the plot.
firstAxisylim (tuple, optional) – Y-axis limits for the first axis.
secondAxisylim (tuple, optional) – Y-axis limits for the second axis.
thirdAxisylim (tuple, optional) – Y-axis limits for the third axis.
- Returns:
Figure and axes objects.
- Return type:
tuple