-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timeseries plot style #465
base: main
Are you sure you want to change the base?
Changes from all commits
27ac391
c972683
3619190
72d3210
dfef139
a68fcfd
320563d
d55b4c7
d2d57e3
4446709
3a1fcba
0f57302
1a70efb
13a7163
3f941aa
f4d22ff
5cf2d03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
_xtick_directional, | ||
_ytick_directional, | ||
quantiles_xy, | ||
_check_kwarg_and_convert_to_list, | ||
) | ||
from ..plotting import taylor_diagram, scatter, TaylorPoint | ||
from ..settings import options | ||
|
@@ -62,6 +63,8 @@ def timeseries( | |
ax=None, | ||
figsize: Tuple[float, float] | None = None, | ||
backend: str = "matplotlib", | ||
style: list[str] | str | None = None, | ||
color: list[str] | tuple | str | None = None, | ||
**kwargs, | ||
): | ||
"""Timeseries plot showing compared data: observation vs modelled | ||
|
@@ -79,32 +82,66 @@ def timeseries( | |
backend : str, optional | ||
use "plotly" (interactive) or "matplotlib" backend, | ||
by default "matplotlib" | ||
style: list of str, optional | ||
containing line styles of the model results. Cannot be passed together with color input. | ||
by default None | ||
color: list of str, optional | ||
containing colors of the model results. | ||
If len(colors) == num_models + 1, the first color will be used for the observations. | ||
Cannot be passed together with style input. | ||
by default None | ||
**kwargs | ||
other keyword arguments to fig.update_layout (plotly backend) | ||
|
||
Returns | ||
------- | ||
matplotlib.axes.Axes or plotly.graph_objects.Figure | ||
""" | ||
|
||
from ._comparison import MOD_COLORS | ||
|
||
cmp = self.comparer | ||
|
||
if title is None: | ||
title = cmp.name | ||
|
||
if color is not None and style is not None: | ||
raise ValueError( | ||
"It is not possible to pass both the color argument and the style argument. Choose one." | ||
) | ||
|
||
# Color for observations: | ||
obs_color = cmp.data[cmp._obs_name].attrs["color"] | ||
|
||
# if color is None and style is None: # Use default values for colors | ||
# from ._comparison import MOD_COLORS | ||
|
||
# color = MOD_COLORS[: cmp.n_models] | ||
|
||
color, style = _check_kwarg_and_convert_to_list(color, style, cmp.n_models) | ||
|
||
if color is not None and len(color) > cmp.n_models: | ||
# If more than n_models colors is given, the first color is used for the observations | ||
obs_color = color[0] | ||
color = color[1:] | ||
|
||
if backend == "matplotlib": | ||
fig, ax = _get_fig_ax(ax, figsize) | ||
for j in range(cmp.n_models): | ||
key = cmp.mod_names[j] | ||
mod = cmp.raw_mod_data[key]._values_as_series | ||
mod.plot(ax=ax, color=MOD_COLORS[j]) | ||
if style is not None: | ||
mod.plot(ax=ax, style=style[j]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest to add a check (outside the loop) that the length of the style list is the same as the number of models (or models+1 obs, see comment below). |
||
else: | ||
if color is None: | ||
color = MOD_COLORS | ||
mod.plot(ax=ax, color=color[j]) | ||
|
||
ax.scatter( | ||
cmp.time, | ||
cmp.data[cmp._obs_name].values, | ||
marker=".", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style does not affect the observations, is this the intended behaviour? |
||
color=cmp.data[cmp._obs_name].attrs["color"], | ||
color=obs_color, | ||
) | ||
ax.set_ylabel(cmp._unit_text) | ||
ax.legend([*cmp.mod_names, cmp._obs_name]) | ||
|
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove unused code