Skip to content
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

Update coloring for graphs #1056

Merged
merged 7 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion darts/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -2989,6 +2989,7 @@ def plot(
central_quantile: Union[float, str] = 0.5,
low_quantile: Optional[float] = 0.05,
high_quantile: Optional[float] = 0.95,
default_formatting: bool = True,
*args,
**kwargs,
):
Expand All @@ -3013,6 +3014,8 @@ def plot(
The quantile to use for the upper bound of the plotted confidence interval. Similar to `central_quantile`,
this is applied to each component separately (i.e., displaying marginal distributions). No confidence
interval is shown if `high_quantile` is None (default 0.95).
default_formatting
Whether or not to use the darts default scheme.
args
some positional arguments for the `plot()` method
kwargs
Expand Down Expand Up @@ -3080,7 +3083,7 @@ def plot(
kwargs["label"] = label_to_use

p = central_series.plot(*args, **kwargs)
color_used = p[0].get_color()
color_used = p[0].get_color() if default_formatting else None
kwargs["alpha"] = alpha if alpha is not None else alpha_confidence_intvls

# Optionally show confidence intervals
Expand Down
39 changes: 31 additions & 8 deletions darts/utils/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ def plot_acf(
bartlett_confint: bool = True,
fig_size: Tuple[int, int] = (10, 5),
axis: Optional[plt.axis] = None,
default_formatting: bool = True,
) -> None:
"""
Plots the ACF of `ts`, highlighting it at lag `m`, with corresponding significance interval.
Expand All @@ -597,6 +598,8 @@ def plot_acf(
The size of the figure to be displayed.
axis
Optionally, an axis object to plot the ACF on.
default_formatting
Whether or not to use the darts default scheme.

References
----------
Expand Down Expand Up @@ -633,21 +636,28 @@ def plot_acf(
axis.plot(
(i, i),
(0, r[i]),
color=("#b512b8" if m is not None and i == m else "black"),
color=("#b512b8" if m is not None and i == m else "black")
if default_formatting
else None,
lw=(1 if m is not None and i == m else 0.5),
)

# Adjusts the upper band of the confidence interval to center it on the x axis.
upp_band = [confint[lag][1] - r[lag] for lag in range(1, max_lag + 1)]

# Setting color t0 None overrides custom settings
extra_arguments = {}
if default_formatting:
extra_arguments["color"] = "#003DFD"

axis.fill_between(
np.arange(1, max_lag + 1),
upp_band,
[-x for x in upp_band],
color="#003DFD",
alpha=0.25,
alpha=0.25 if default_formatting else None,
**extra_arguments,
)
axis.plot((0, max_lag + 1), (0, 0), color="black")
axis.plot((0, max_lag + 1), (0, 0), color="black" if default_formatting else None)


def plot_pacf(
Expand All @@ -658,6 +668,7 @@ def plot_pacf(
alpha: float = 0.05,
fig_size: Tuple[int, int] = (10, 5),
axis: Optional[plt.axis] = None,
default_formatting: bool = True,
) -> None:
"""
Plots the Partial ACF of `ts`, highlighting it at lag `m`, with corresponding significance interval.
Expand Down Expand Up @@ -691,6 +702,8 @@ def plot_pacf(
The size of the figure to be displayed.
axis
Optionally, an axis object to plot the ACF on.
default_formatting
Whether or not to use the darts default scheme.

References
----------
Expand Down Expand Up @@ -721,21 +734,31 @@ def plot_pacf(
axis.plot(
(i, i),
(0, r[i]),
color=("#b512b8" if m is not None and i == m else "black"),
color=(
"#b512b8"
if m is not None and i == m
else "black"
if default_formatting
else None
),
lw=(1 if m is not None and i == m else 0.5),
)

# Adjusts the upper band of the confidence interval to center it on the x axis.
upp_band = [confint[lag][1] - r[lag] for lag in range(1, max_lag + 1)]

extra_arguments = {}
if default_formatting:
extra_arguments["color"] = "#003DFD"

axis.fill_between(
np.arange(1, max_lag + 1),
upp_band,
[-x for x in upp_band],
color="#003DFD",
alpha=0.25,
alpha=0.25 if default_formatting else None,
**extra_arguments,
)
axis.plot((0, max_lag + 1), (0, 0), color="black")
axis.plot((0, max_lag + 1), (0, 0), color="black" if default_formatting else None)


def plot_hist(
Expand Down