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

Make ecdf_line a step line #169

Merged
merged 2 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/arviz_plots/backend/bokeh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,12 @@ def scatter(
return target.scatter(np.atleast_1d(x), np.atleast_1d(y), **kwargs)


def step(x, y, target, *, color=unset, alpha=unset, width=unset, linestyle=unset, **artist_kws):
"""Interface to bokeh for a step line."""
kwargs = {"color": color, "alpha": alpha, "line_width": width, "line_dash": linestyle}
return target.step(np.atleast_1d(x), np.atleast_1d(y), **_filter_kwargs(kwargs, artist_kws))


def text(
x,
y,
Expand Down
7 changes: 7 additions & 0 deletions src/arviz_plots/backend/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,13 @@ def scatter(
return target.scatter(x, y, **_filter_kwargs(kwargs, None, artist_kws))


def step(x, y, target, *, color=unset, alpha=unset, width=unset, linestyle=unset, **artist_kws):
"""Interface to matplotlib for a step line."""
artist_kws.setdefault("zorder", 2)
kwargs = {"color": color, "alpha": alpha, "linewidth": width, "linestyle": linestyle}
return target.step(x, y, **_filter_kwargs(kwargs, Line2D, artist_kws))[0]


def text(
x,
y,
Expand Down
15 changes: 15 additions & 0 deletions src/arviz_plots/backend/none/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,21 @@ def scatter(
return artist_element


def step(x, y, target, *, color=unset, alpha=unset, width=unset, linestyle=unset, **artist_kws):
"""Interface to a step line."""
kwargs = {"color": color, "alpha": alpha, "width": width, "linestyle": linestyle}
if not ALLOW_KWARGS and artist_kws:
raise ValueError("artist_kws not empty")
artist_element = {
"function": "line",
"x": np.atleast_1d(x),
"y": np.atleast_1d(y),
**_filter_kwargs(kwargs, artist_kws),
}
target.append(artist_element)
return artist_element


def text(
x,
y,
Expand Down
17 changes: 17 additions & 0 deletions src/arviz_plots/backend/plotly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,23 @@ def scatter(
return scatter_object


def step(x, y, target, *, color=unset, alpha=unset, width=unset, linestyle=unset, **artist_kws):
"""Interface to plotly for a step line."""
artist_kws.setdefault("showlegend", False)
line_kwargs = {"color": color, "width": width, "dash": linestyle}
line_artist_kws = artist_kws.pop("line", {"shape": "hv"}).copy()
kwargs = {"opacity": alpha}
line_object = go.Scatter(
x=np.atleast_1d(x),
y=np.atleast_1d(y),
mode="lines",
line=_filter_kwargs(line_kwargs, line_artist_kws),
**_filter_kwargs(kwargs, artist_kws),
)
target.add_trace(line_object)
return line_object


def text(
x,
y,
Expand Down
4 changes: 2 additions & 2 deletions src/arviz_plots/visuals/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ def scatter_xy(da, target, backend, x=None, y=None, **kwargs):


def ecdf_line(values, target, backend, **kwargs):
"""Plot an ecdf line."""
"""Plot a step line."""
plot_backend = import_module(f"arviz_plots.backend.{backend}")
return plot_backend.line(values.sel(plot_axis="x"), values.sel(plot_axis="y"), target, **kwargs)
return plot_backend.step(values.sel(plot_axis="x"), values.sel(plot_axis="y"), target, **kwargs)


def vline(values, target, backend, **kwargs):
Expand Down