Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Alina Voilova committed Nov 21, 2023
1 parent cbef5e7 commit 5ce6839
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 additions & 1 deletion portfolyo/core/mixins/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,13 @@ def plot_to_ax(
raise ValueError(
f"For this PfLine, parameter ``col`` must be one of {', '.join(self.kind.available)}; got {col}."
)
# if len(self.items()) == 0:
# print("This PFline doesn't have any children")
# for (name, child) in self.items():
# vis.plot_timeseries(ax, getattr(self, name), how, labelfmt, **kwargs)
vis.plot_timeseries(ax, getattr(self, col), how, labelfmt, **kwargs)

def plot(self: PfLine, cols: str = None) -> plt.Figure:
def plot(self: PfLine, cols: str = None, children: bool = False) -> plt.Figure:
"""Plot one or more timeseries of the PfLine.
Parameters
Expand All @@ -79,6 +83,8 @@ def plot(self: PfLine, cols: str = None) -> plt.Figure:
The columns to plot. Default: plot volume (in [MW] for daily values and
shorter, [MWh] for monthly values and longer) and price `p` [Eur/MWh]
(if available).
children : bool, optional (default: False)
If True, plot also the direct children of the PfLine.
Returns
-------
Expand Down Expand Up @@ -110,6 +116,20 @@ def plot(self: PfLine, cols: str = None) -> plt.Figure:
kwargs = defaultkwargs(col, is_category)
s = getattr(self, col)
vis.plot_timeseries(ax, s, **kwargs)
for name, child in self.items():
# kwargs = defaultkwargs(col, is_category)
s = getattr(child, col)
# the first time: set the type of axes to the type of the s series type
# the second type: tries to convert the unit that were set to base units
# but it fails
# setattr(ax, "_unit", None)
vis.plot_timeseries(ax, s, **kwargs)

# for (name, child) in self.items():
# for col, ax in zipped:
# kwargs = defaultkwargs(col, is_category)
# s = getattr(child, col)
# vis.plot_timeseries(ax, s, **kwargs)

return fig

Expand Down
2 changes: 1 addition & 1 deletion portfolyo/visualize/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def prepare_ax_and_s(ax: plt.Axes, s: pd.Series, unit=None) -> pd.Series:
raise ValueError(
f"Cannot plot series with units {s.pint.units} on axes with units {axunit}."
)
return s.astype(axunit)
return s.astype(f"pint[{axunit}]")

# Axes does not have unit.
if unit is not None:
Expand Down

0 comments on commit 5ce6839

Please sign in to comment.