Skip to content

Commit c821e08

Browse files
committed
Add test that polygon tuple markers work.
1 parent b89936c commit c821e08

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

lib/matplotlib/tests/test_marker.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import numpy as np
22
from matplotlib import markers
33
from matplotlib.path import Path
4+
from matplotlib.testing.decorators import check_figures_equal
45

56
import pytest
67

@@ -26,3 +27,60 @@ def test_marker_path():
2627
path = Path([[0, 0], [1, 0]], [Path.MOVETO, Path.LINETO])
2728
# Checking this doesn't fail.
2829
marker_style.set_marker(path)
30+
31+
32+
class UnsnappedMarkerStyle(markers.MarkerStyle):
33+
"""
34+
A MarkerStyle where the snap threshold is force-disabled.
35+
36+
This is used to compare to polygon/star/asterisk markers which do not have
37+
any snap threshold set.
38+
"""
39+
def _recache(self):
40+
super()._recache()
41+
self._snap_threshold = None
42+
43+
44+
@check_figures_equal()
45+
def test_poly_marker(fig_test, fig_ref):
46+
ax_test = fig_test.add_subplot()
47+
ax_ref = fig_ref.add_subplot()
48+
49+
# Note, some reference sizes must be different because they have unit
50+
# *length*, while polygon markers are inscribed in a circle of unit
51+
# *radius*. This introduces a factor of np.sqrt(2), but since size is
52+
# squared, that becomes 2.
53+
size = 20**2
54+
55+
# Squares
56+
ax_test.scatter([0], [0], marker=(4, 0, 45), s=size)
57+
ax_ref.scatter([0], [0], marker='s', s=size/2)
58+
59+
# Diamonds, with and without rotation argument
60+
ax_test.scatter([1], [1], marker=(4, 0), s=size)
61+
ax_ref.scatter([1], [1], marker=UnsnappedMarkerStyle('D'), s=size/2)
62+
ax_test.scatter([1], [1.5], marker=(4, 0, 0), s=size)
63+
ax_ref.scatter([1], [1.5], marker=UnsnappedMarkerStyle('D'), s=size/2)
64+
65+
# Pentagon, with and without rotation argument
66+
ax_test.scatter([2], [2], marker=(5, 0), s=size)
67+
ax_ref.scatter([2], [2], marker=UnsnappedMarkerStyle('p'), s=size)
68+
ax_test.scatter([2], [2.5], marker=(5, 0, 0), s=size)
69+
ax_ref.scatter([2], [2.5], marker=UnsnappedMarkerStyle('p'), s=size)
70+
71+
# Hexagon, with and without rotation argument
72+
ax_test.scatter([3], [3], marker=(6, 0), s=size)
73+
ax_ref.scatter([3], [3], marker='h', s=size)
74+
ax_test.scatter([3], [3.5], marker=(6, 0, 0), s=size)
75+
ax_ref.scatter([3], [3.5], marker='h', s=size)
76+
77+
# Rotated hexagon
78+
ax_test.scatter([4], [4], marker=(6, 0, 30), s=size)
79+
ax_ref.scatter([4], [4], marker='H', s=size)
80+
81+
# Octagons
82+
ax_test.scatter([5], [5], marker=(8, 0, 22.5), s=size)
83+
ax_ref.scatter([5], [5], marker=UnsnappedMarkerStyle('8'), s=size)
84+
85+
ax_test.set(xlim=(-0.5, 5.5), ylim=(-0.5, 5.5))
86+
ax_ref.set(xlim=(-0.5, 5.5), ylim=(-0.5, 5.5))

0 commit comments

Comments
 (0)