Skip to content

Commit

Permalink
Fix Plot with no variance in orient dimension (#3084)
Browse files Browse the repository at this point in the history
* Fix Plot with no variance in orient dimension

* Update release notes

* Update test with new correct behavior
  • Loading branch information
mwaskom committed Oct 15, 2022
1 parent 1d70f58 commit a02b6bf
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions doc/whatsnew/v0.12.1.rst
Expand Up @@ -22,6 +22,8 @@ v0.12.1 (Unreleased)

- |Fix| Made :class:`objects.PolyFit` robust to missing data (:pr:`3010`).

- |Fix| Fixed a bug in :class:`objects.Plot` that occurred when the orient coordinate data had zero variance (:pr:`3084`).

- |Fix| Fixed a regression in :func:`kdeplot` where passing `cmap` for an unfilled bivariate plot would raise an exception (:pr:`3065`).

- |Fix| Addressed a performance regression in :func:`lineplot` with a large number of unique x values (:pr:`3081`).
Expand Down
7 changes: 6 additions & 1 deletion seaborn/_core/scales.py
Expand Up @@ -94,7 +94,12 @@ def set_default_locators_and_formatters(self, axis):
return InternalScale(name, (forward, inverse))

def _spacing(self, x: Series) -> float:
return self._spacer(x)
space = self._spacer(x)
if np.isnan(space):
# This happens when there is no variance in the orient coordinate data
# Not exactly clear what the right default is, but 1 seems reasonable?
return 1
return space

def _setup(
self, data: Series, prop: Property, axis: Axis | None = None,
Expand Down
8 changes: 8 additions & 0 deletions tests/_core/test_plot.py
Expand Up @@ -683,6 +683,14 @@ def test_empty(self):
Plot().plot()
assert m.n_splits == 0

def test_no_orient_variance(self):

x, y = [0, 0], [1, 2]
m = MockMark()
Plot(x, y).add(m).plot()
assert_array_equal(m.passed_data[0]["x"], x)
assert_array_equal(m.passed_data[0]["y"], y)

def test_single_split_single_layer(self, long_df):

m = MockMark()
Expand Down
5 changes: 3 additions & 2 deletions tests/_marks/test_line.py
Expand Up @@ -253,8 +253,9 @@ def test_single_orient_value(self):
y = [1, 2, 3]
p = Plot(x, y).add(Lines()).plot()
lines, = p._figure.axes[0].collections
paths, = lines.get_paths()
assert paths.vertices.shape == (0, 2)
verts = lines.get_paths()[0].vertices.T
assert_array_equal(verts[0], x)
assert_array_equal(verts[1], y)


class TestRange:
Expand Down

0 comments on commit a02b6bf

Please sign in to comment.