8000 Scatter ravel is performed before _process_unit_info() is called. · matplotlib/matplotlib@2a54864 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2a54864

Browse files
committed
Scatter ravel is performed before _process_unit_info() is called.
1 parent 4aa7efe commit 2a54864

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4657,14 +4657,14 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
46574657
# further processed by the rest of the function
46584658
linewidths = kwargs.pop('linewidth', None)
46594659
edgecolors = kwargs.pop('edgecolor', None)
4660-
# Process **kwargs to handle aliases, conflicts with explicit kwargs:
4661-
x, y = self._process_unit_info([("x", x), ("y", y)], kwargs)
46624660
# np.ma.ravel yields an ndarray, not a masked array,
46634661
# unless its argument is a masked array.
46644662
x = np.ma.ravel(x)
46654663
y = np.ma.ravel(y)
46664664
if x.size != y.size:
46674665
raise ValueError("x and y must be the same size")
4666+
# Process **kwargs to handle aliases, conflicts with explicit kwargs:
4667+
x, y = self._process_unit_info([("x", x), ("y", y)], kwargs)
46684668

46694669
if s is None:
46704670
s = (20 if mpl.rcParams['_internal.classic_mode'] else

lib/matplotlib/tests/test_category.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,13 @@ def test_update_plot(self, plotter):
249249
failing_test_cases = [("mixed", ['A', 3.14]),
250250
("number integer", ['1', 1]),
251251
("string integer", ['42', 42]),
252+
("nested categorical", [["a", "b"], ["c", "d"]]),
252253
("missing", ['12', np.nan])]
253254

254255
fids, fvalues = zip(*failing_test_cases)
255256

256-
plotters = [Axes.scatter, Axes.bar,
257+
plotters = [pytest.param(Axes.scatter, marks=pytest.mark.xfail),
258+
Axes.bar,
257259
pytest.param(Axes.plot, marks=pytest.mark.xfail)]
258260

259261
@pytest.mark.parametrize("plotter", plotters)
@@ -321,3 +323,33 @@ def test_set_lim():
321323
ax.plot(["a", "b", "c", "d"], [1, 2, 3, 4])
322324
with warnings.catch_warnings():
323325
ax.set_xlim("b", "c")
326+
327+
328+
categorical_examples = [("nested categorical", [["a", "b"], ["c", "d"]]),
329+
("nested with nan", [['0', np.nan], ["aa", "bb"]]),
330+
("nested mixed", [[1, 'a'], ['b', np.nan]])]
331+
cids, cvalues = zip(*categorical_examples)
332+
333+
334+
@pytest.mark.parametrize("xdata", cvalues, ids=cids)
335+
@pytest.mark.parametrize("ydata", cvalues, ids=cids)
336+
def test_nested_categorical(xdata, ydata):
337+
ax = plt.figure().subplots()
338+
ax.scatter(xdata, ydata)
339+
340+
xtexts = [xelement._text for xelement in ax.get_xticklabels()]
341+
342+
assert np.all(xtexts == np.ma.ravel(xdata))
343+
344+
345+
@pytest.mark.parametrize("xdata", cvalues, ids=cids)
346+
def test_nested_categorical_and_numerical(xdata):
347+
ydata = [[0, 1], [2, 3]]
348+
ax = plt.figure().subplots()
349+
splot = ax.scatter(xdata, ydata)
350+
351+
xtexts = [xelement._text for xelement in ax.get_xticklabels()]
352+
y_offset_processed = list(zip(*splot.get_offsets()))[1]
353+
354+
assert np.all(xtexts == np.ma.ravel(xdata))
355+
assert np.all(np.ma.ravel(ydata) == y_offset_processed)

0 commit comments

Comments
 (0)
0