diff --git a/lib/matplotlib/markers.py b/lib/matplotlib/markers.py index d5b051709ef6..366a17e4fceb 100644 --- a/lib/matplotlib/markers.py +++ b/lib/matplotlib/markers.py @@ -249,12 +249,14 @@ def get_marker(self): return self._marker def set_marker(self, marker): - if (isinstance(marker, Sized) and len(marker) in (2, 3) and + if (isinstance(marker, np.ndarray) and marker.ndim == 2 and + marker.shape[1] == 2): + self._marker_function = self._set_vertices + elif (isinstance(marker, Sized) and len(marker) in (2, 3) and marker[1] in (0, 1, 2, 3)): self._marker_function = self._set_tuple_marker - elif isinstance(marker, np.ndarray): - self._marker_function = self._set_vertices - elif not isinstance(marker, list) and marker in self.markers: + elif (not isinstance(marker, (np.ndarray, list)) and + marker in self.markers): self._marker_function = getattr( self, '_set_' + self.markers[marker]) elif is_string_like(marker) and is_math_text(marker): diff --git a/lib/matplotlib/tests/test_marker.py b/lib/matplotlib/tests/test_marker.py new file mode 100644 index 000000000000..e2290f029dcc --- /dev/null +++ b/lib/matplotlib/tests/test_marker.py @@ -0,0 +1,20 @@ +import numpy as np +from matplotlib import markers + +import pytest + + +def test_markers_valid(): + marker_style = markers.MarkerStyle() + mrk_array = np.array([[-0.5, 0], + [0.5, 0]]) + # Checking this doesn't fail. + marker_style.set_marker(mrk_array) + + +def test_markers_invalid(): + marker_style = markers.MarkerStyle() + mrk_array = np.array([[-0.5, 0, 1, 2, 3]]) + # Checking this does fail. + with pytest.raises(ValueError): + marker_style.set_marker(mrk_array)