Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 98a9347

Browse files
committed
Merge pull request #7809 from lkilcher/marker_verts_bug
Fix for marker verts bug
1 parent fbe562c commit 98a9347

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

lib/matplotlib/markers.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,14 @@ def get_marker(self):
246246
return self._marker
247247

248248
def set_marker(self, marker):
249-
if (iterable(marker) and len(marker) in (2, 3) and
249+
if (isinstance(marker, np.ndarray) and marker.ndim == 2 and
250+
marker.shape[1] == 2):
251+
self._marker_function = self._set_vertices
252+
elif (iterable(marker) and len(marker) in (2, 3) and
250253
marker[1] in (0, 1, 2, 3)):
251254
self._marker_function = self._set_tuple_marker
252-
elif isinstance(marker, np.ndarray):
253-
self._marker_function = self._set_vertices
254-
elif not isinstance(marker, list) and marker in self.markers:
255+
elif (not isinstance(marker, (np.ndarray, list)) and
256+
marker in self.markers):
255257
self._marker_function = getattr(
256258
self, '_set_' + self.markers[marker])
257259
elif is_string_like(marker) and is_math_text(marker):

lib/matplotlib/tests/test_marker.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import numpy as np
2+
from matplotlib import markers
3+
4+
import pytest
5+
6+
7+
def test_markers_valid():
8+
marker_style = markers.MarkerStyle()
9+
mrk_array = np.array([[-0.5, 0],
10+
[0.5, 0]])
11+
# Checking this doesn't fail.
12+
marker_style.set_marker(mrk_array)
13+
14+
15+
def test_markers_invalid():
16+
marker_style = markers.MarkerStyle()
17+
mrk_array = np.array([[-0.5, 0, 1, 2, 3]])
18+
# Checking this does fail.
19+
with pytest.raises(ValueError):
20+
marker_style.set_marker(mrk_array)

0 commit comments

Comments
 (0)