1
1
import numpy as np
2
2
from matplotlib import markers
3
3
from matplotlib .path import Path
4
+ from matplotlib .testing .decorators import check_figures_equal
4
5
5
6
import pytest
6
7
@@ -26,3 +27,61 @@ def test_marker_path():
26
27
path = Path ([[0 , 0 ], [1 , 0 ]], [Path .MOVETO , Path .LINETO ])
27
28
# Checking this doesn't fail.
28
29
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*.
52
+ size = 20
53
+
54
+ # Squares
55
+ ax_test .plot ([0 ] * 3 , marker = (4 , 0 , 45 ), markersize = size )
56
+ ax_ref .plot ([0 ] * 3 , marker = 's' , markersize = size / np .sqrt (2 ))
57
+
58
+ # Diamonds, with and without rotation argument
59
+ ax_test .plot ([1 ] * 3 , marker = (4 , 0 ), markersize = size )
60
+ ax_ref .plot ([1 ] * 3 , marker = UnsnappedMarkerStyle ('D' ),
61
+ markersize = size / np .sqrt (2 ))
62
+ ax_test .plot ([1.5 ] * 3 , marker = (4 , 0 , 0 ), markersize = size )
63
+ ax_ref .plot ([1.5 ] * 3 , marker = UnsnappedMarkerStyle ('D' ),
64
+ markersize = size / np .sqrt (2 ))
65
+
66
+ # Pentagon, with and without rotation argument
67
+ ax_test .plot ([2 ] * 3 , marker = (5 , 0 ), markersize = size )
68
+ ax_ref .plot ([2 ] * 3 , marker = UnsnappedMarkerStyle ('p' ), markersize = size )
69
+ ax_test .plot ([2.5 ] * 3 , marker = (5 , 0 , 0 ), markersize = size )
70
+ ax_ref .plot ([2.5 ] * 3 , marker = UnsnappedMarkerStyle ('p' ), markersize = size )
71
+
72
+ # Hexagon, with and without rotation argument
73
+ ax_test .plot ([3 ] * 3 , marker = (6 , 0 ), markersize = size )
74
+ ax_ref .plot ([3 ] * 3 , marker = 'h' , markersize = size )
75
+ ax_test .plot ([3.5 ] * 3 , marker = (6 , 0 , 0 ), markersize = size )
76
+ ax_ref .plot ([3.5 ] * 3 , marker = 'h' , markersize = size )
77
+
78
+ # Rotated hexagon
79
+ ax_test .plot ([4 ] * 3 , marker = (6 , 0 , 30 ), markersize = size )
80
+ ax_ref .plot ([4 ] * 3 , marker = 'H' , markersize = size )
81
+
82
+ # Octagons
83
+ ax_test .plot ([5 ] * 3 , marker = (8 , 0 , 22.5 ), markersize = size )
84
+ ax_ref .plot ([5 ] * 3 , marker = UnsnappedMarkerStyle ('8' ), markersize = size )
85
+
86
+ ax_test .set (xlim = (- 0.5 , 2.5 ), ylim = (- 0.5 , 5.5 ))
87
+ ax_ref .set (xlim = (- 0.5 , 2.5 ), ylim = (- 0.5 , 5.5 ))
0 commit comments