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

Skip to content

Commit 27b3be5

Browse files
committed
Filled + and x markers
The rationale for the addition of these symbols is; to allow a grammar based plotting package to conveniently use the common plotting symbols (circle, square, triangle, plus and x) and not have to deal with some of them not being fillable.
1 parent f3b6c4e commit 27b3be5

File tree

4 files changed

+98
-7
lines changed

4 files changed

+98
-7
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Filled ``+`` and ``x`` markers
2+
------------------------------
3+
4+
New fillable *plus* and *x* markers have been added. See
5+
the :mod:`~matplotlib.markers` module and
6+
:ref:`marker reference <lines_bars_and_markers-marker_reference>`
7+
examples.

lib/matplotlib/markers.py

Lines changed: 90 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
"d" thin_diamond
3232
"|" vline
3333
"_" hline
34+
"P" plus (filled)
35+
"X" x (filled)
3436
TICKLEFT tickleft
3537
TICKRIGHT tickright
3638
TICKUP tickup
@@ -126,6 +128,8 @@ class MarkerStyle(object):
126128
'd': 'thin_diamond',
127129
'|': 'vline',
128130
'_': 'hline',
131+
'P': 'plus_filled',
132+
'X': 'x_filled',
129133
TICKLEFT: 'tickleft',
130134
TICKRIGHT: 'tickright',
131135
TICKUP: 'tickup',
@@ -147,7 +151,8 @@ class MarkerStyle(object):
147151
# Just used for informational purposes. is_filled()
148152
# is calculated in the _set_* functions.
149153
filled_markers = (
150-
'o', 'v', '^', '<', '>', '8', 's', 'p', '*', 'h', 'H', 'D', 'd')
154+
'o', 'v', '^', '<', '>', '8', 's', 'p', '*', 'h', 'H', 'D', 'd',
155+
'P', 'X')
151156

152157
fillstyles = ('full', 'left', 'right', 'bottom', 'top', 'none')
153158
_half_fillstyles = ('left', 'right', 'bottom', 'top')
@@ -818,13 +823,92 @@ def _set_caretrightbase(self):
818823
self._path = self._caret_path_base
819824
self._joinstyle = 'miter'
820825

821-
_x_path = Path([[-1.0, -1.0], [1.0, 1.0],
822-
[-1.0, 1.0], [1.0, -1.0]],
823-
[Path.MOVETO, Path.LINETO,
824-
Path.MOVETO, Path.LINETO])
825-
826826
def _set_x(self):
827827
self._transform = Affine2D().scale(0.5)
828828
self._snap_threshold = 3.0
829829
self._filled = False
830830
self._path = self._x_path
831+
832+
_plus_filled_path = Path([(1/3, 0), (2/3, 0), (2/3, 1/3),
833+
(1, 1/3), (1, 2/3), (2/3, 2/3),
834+
(2/3, 1), (1/3, 1), (1/3, 2/3),
835+
(0, 2/3), (0, 1/3), (1/3, 1/3),
836+
(1/3, 0)],
837+
[Path.MOVETO, Path.LINETO, Path.LINETO,
838+
Path.LINETO, Path.LINETO, Path.LINETO,
839+
Path.LINETO, Path.LINETO, Path.LINETO,
840+
Path.LINETO, Path.LINETO, Path.LINETO,
841+
Path.CLOSEPOLY])
842+
843+
_plus_filled_path_t = Path([(1, 1/2), (1, 2/3), (2/3, 2/3),
844+
(2/3, 1), (1/3, 1), (1/3, 2/3),
845+
(0, 2/3), (0, 1/2), (1, 1/2)],
846+
[Path.MOVETO, Path.LINETO, Path.LINETO,
847+
Path.LINETO, Path.LINETO, Path.LINETO,
848+
Path.LINETO, Path.LINETO,
849+
Path.CLOSEPOLY])
850+
851+
def _set_plus_filled(self):
852+
self._transform = Affine2D().translate(-0.5, -0.5)
853+
self._snap_threshold = 5.0
854+
self._joinstyle = 'miter'
855+
fs = self.get_fillstyle()
856+
if not self._half_fill():
857+
self._path = self._plus_filled_path
858+
else:
859+
# Rotate top half path to support all partitions
860+
if fs == 'top':
861+
rotate, rotate_alt = 0, 180
862+
elif fs == 'bottom':
863+
rotate, rotate_alt = 180, 0
864+
elif fs == 'left':
865+
rotate, rotate_alt = 90, 270
866+
else:
867+
rotate, rotate_alt = 270, 90
868+
869+
self._path = self._plus_filled_path_t
870+
self._alt_path = self._plus_filled_path_t
871+
self._alt_transform = Affine2D().translate(-0.5, -0.5)
872+
self._transform.rotate_deg(rotate)
873+
self._alt_transform.rotate_deg(rotate_alt)
874+
875+
_x_filled_path = Path([(0.25, 0), (0.5, 0.25), (0.75, 0), (1, 0.25),
876+
(0.75, 0.5), (1, 0.75), (0.75, 1), (0.5, 0.75),
877+
(0.25, 1), (0, 0.75), (0.25, 0.5), (0, 0.25),
878+
(0.25, 0)],
879+
[Path.MOVETO, Path.LINETO, Path.LINETO,
880+
Path.LINETO, Path.LINETO, Path.LINETO,
881+
Path.LINETO, Path.LINETO, Path.LINETO,
882+
Path.LINETO, Path.LINETO, Path.LINETO,
883+
Path.CLOSEPOLY])
884+
885+
_x_filled_path_t = Path([(0.75, 0.5), (1, 0.75), (0.75, 1),
886+
(0.5, 0.75), (0.25, 1), (0, 0.75),
887+
(0.25, 0.5), (0.75, 0.5)],
888+
[Path.MOVETO, Path.LINETO, Path.LINETO,
889+
Path.LINETO, Path.LINETO, Path.LINETO,
890+
Path.LINETO, Path.CLOSEPOLY])
891+
892+
def _set_x_filled(self):
893+
self._transform = Affine2D().translate(-0.5, -0.5)
894+
self._snap_threshold = 5.0
895+
self._joinstyle = 'miter'
896+
fs = self.get_fillstyle()
897+
if not self._half_fill():
898+
self._path = self._x_filled_path
899+
else:
900+
# Rotate top half path to support all partitions
901+
if fs == 'top':
902+
rotate, rotate_alt = 0, 180
903+
elif fs == 'bottom':
904+
rotate, rotate_alt = 180, 0
905+
elif fs == 'left':
906+
rotate, rotate_alt = 90, 270
907+
else:
908+
rotate, rotate_alt = 270, 90
909+
910+
self._path = self._x_filled_path_t
911+
self._alt_path = self._x_filled_path_t
912+
self._alt_transform = Affine2D().translate(-0.5, -0.5)
913+
self._transform.rotate_deg(rotate)
914+
self._alt_transform.rotate_deg(rotate_alt)

lib/matplotlib/tests/test_lines.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def test_marker_fill_styles():
180180
markeredgewidth=2)
181181

182182
ax.set_ylim([0, 7.5])
183-
ax.set_xlim([-5, 135])
183+
ax.set_xlim([-5, 155])
184184

185185

186186
@image_comparison(baseline_images=['scaled_lines'], style='default')

0 commit comments

Comments
 (0)