Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fb9e723 commit d84f4a7Copy full SHA for d84f4a7
2 files changed
lib/matplotlib/axes/_axes.py
@@ -4281,9 +4281,15 @@ def invalid_shape_exception(csize, xsize):
4281
except ValueError:
4282
pass # Failed to convert to float array; must be color specs.
4283
else:
4284
+ # handle the documented special case of a 2D array with 1
4285
+ # row which as RGB(A) to broadcast.
4286
+ if c.shape == (1, 4) or c.shape == (1, 3):
4287
+ c_is_mapped = False
4288
+ if c.size != xsize:
4289
+ valid_shape = False
4290
# If c can be either mapped values or a RGB(A) color, prefer
4291
# the former if shapes match, the latter otherwise.
- if c.size == xsize:
4292
+ elif c.size == xsize:
4293
c = c.ravel()
4294
c_is_mapped = True
4295
else: # Wrong size; it must not be intended for mapping.
lib/matplotlib/tests/test_axes.py
@@ -1968,6 +1968,22 @@ def get_next_color():
1968
c=c_case, edgecolors="black", kwargs={}, xsize=xsize,
1969
get_next_color_func=get_next_color)
1970
1971
+ @pytest.mark.style('default')
1972
+ @check_figures_equal(extensions=["png"])
1973
+ def test_scatter_single_color_c(self, fig_test, fig_ref):
1974
+ rgb = [[1, 0.5, 0.05]]
1975
+ rgba = [[1, 0.5, 0.05, .5]]
1976
+
1977
+ # set via color kwarg
1978
+ ax_ref = fig_ref.subplots()
1979
+ ax_ref.scatter(np.ones(3), range(3), color=rgb)
1980
+ ax_ref.scatter(np.ones(4)*2, range(4), color=rgba)
1981
1982
+ # set via broadcasting via c
1983
+ ax_test = fig_test.subplots()
1984
+ ax_test.scatter(np.ones(3), range(3), c=rgb)
1985
+ ax_test.scatter(np.ones(4)*2, range(4), c=rgba)
1986
1987
1988
def _params(c=None, xsize=2, *, edgecolors=None, **kwargs):
1989
return (c, edgecolors, kwargs if kwargs is not None else {}, xsize)
0 commit comments