Skip to content

Commit 4f661d2

Browse files
committed
fix #462
1 parent f8d7949 commit 4f661d2

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

dascore/viz/wiggle.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,22 @@ def wiggle(
9393
>>> _ = patch.viz.wiggle()
9494
"""
9595
ax = _get_ax(ax)
96+
97+
# Handle 1D patches (issue #462)
98+
if len(patch.dims) == 1:
99+
plot_dim = patch.dims[0]
100+
x_values = patch.coords.get_array(plot_dim)
101+
y_values = patch.data
102+
ax.plot(x_values, y_values, color=color, alpha=alpha)
103+
ax.set_xlabel(_get_dim_label(patch, plot_dim))
104+
ax.set_ylabel("amplitude")
105+
# Format time axis if applicable
106+
if np.issubdtype(patch.get_coord(plot_dim).dtype, np.datetime64):
107+
_format_time_axis(ax, plot_dim, "x")
108+
if show:
109+
plt.show()
110+
return ax
111+
96112
assert len(patch.dims) == 2, "Can only make wiggle plot of 2D Patch"
97113
# After transpose selected dim must be axis 0 and other axis 1
98114
patch = patch.transpose(dim, ...)

tests/test_viz/test_wiggle.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,19 @@ def test_show(self, random_patch, monkeypatch):
5454
"""Ensure show path is callable."""
5555
monkeypatch.setattr(plt, "show", lambda: None)
5656
random_patch.viz.wiggle(show=True)
57+
58+
def test_1d_patch(self, random_patch):
59+
"""Test that wiggle works with 1D patches (issue #462)."""
60+
# Create a 1D patch by reducing one dimension
61+
patch_1d = random_patch.mean("distance", dim_reduce="squeeze")
62+
# This should work without raising an assertion error
63+
ax = patch_1d.viz.wiggle()
64+
assert isinstance(ax, plt.Axes)
65+
# The remaining dimension should be on the x-axis
66+
assert patch_1d.dims[0].lower() in ax.get_xlabel().lower()
67+
68+
def test_1d_patch_show(self, random_patch, monkeypatch):
69+
"""Test that show works with 1D patches (issue #462)."""
70+
monkeypatch.setattr(plt, "show", lambda: None)
71+
patch_1d = random_patch.mean("distance", dim_reduce="squeeze")
72+
patch_1d.viz.wiggle(show=True)

0 commit comments

Comments
 (0)