Skip to content

Commit 82ec838

Browse files
committed
Fix half-filled markers protrusion.
Don't let the miter joins protrude by manually cropping them. This is currently only implemented for diamond, but others should work "similarly". However, this reveals a bug(?) in Agg's handling of miter with close corners, which does not handle that case correctly. (pdf, ps, svg, and cairo all handle it fine). Also don't forget a closepoly on half-filled squares.
1 parent 3d5c6d5 commit 82ec838

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

lib/matplotlib/markers.py

+13-11
Original file line numberDiff line numberDiff line change
@@ -519,15 +519,13 @@ def _set_square(self):
519519
if not self._half_fill():
520520
self._path = Path.unit_rectangle()
521521
else:
522-
# Build a bottom filled square out of two rectangles, one filled.
523-
self._path = Path([[0.0, 0.0], [1.0, 0.0], [1.0, 0.5],
524-
[0.0, 0.5], [0.0, 0.0]])
525-
self._alt_path = Path([[0.0, 0.5], [1.0, 0.5], [1.0, 1.0],
526-
[0.0, 1.0], [0.0, 0.5]])
522+
self._path = self._alt_path = Path( # Half-square.
523+
[[0.0, 0.0], [1.0, 0.0], [1.0, 0.5], [0.0, 0.5], [0.0, 0.0]],
524+
closed=True)
527525
fs = self.get_fillstyle()
528526
rotate = {'bottom': 0, 'right': 90, 'top': 180, 'left': 270}[fs]
529527
self._transform.rotate_deg(rotate)
530-
self._alt_transform = self._transform
528+
self._alt_transform = self._transform.frozen().rotate_deg(180)
531529

532530
self._joinstyle = JoinStyle.miter
533531

@@ -537,17 +535,21 @@ def _set_diamond(self):
537535
if not self._half_fill():
538536
self._path = Path.unit_rectangle()
539537
else:
540-
self._path = Path([[0, 0], [1, 0], [1, 1], [0, 0]])
541-
self._alt_path = Path([[0, 0], [0, 1], [1, 1], [0, 0]])
538+
eps = 1e-3 # Don't let the miter joins protrude.
539+
self._path = self._alt_path = Path(
540+
[[eps, eps], [eps, 0], [1, 0], [1, 1-eps], [1-eps, 1-eps],
541+
[eps, eps]], closed=True)
542542
fs = self.get_fillstyle()
543-
rotate = {'right': 0, 'top': 90, 'left': 180, 'bottom': 270}[fs]
543+
rotate = {'bottom': 0, 'right': 90, 'top': 180, 'left': 270}[fs]
544544
self._transform.rotate_deg(rotate)
545-
self._alt_transform = self._transform
546-
self._joinstyle = JoinStyle.miter
545+
self._alt_transform = self._transform.frozen().rotate_deg(180)
546+
self._joinstyle = 'miter'
547547

548548
def _set_thin_diamond(self):
549549
self._set_diamond()
550550
self._transform.scale(0.6, 1.0)
551+
if self._alt_transform:
552+
self._alt_transform.scale(0.6, 1.0)
551553

552554
def _set_pentagon(self):
553555
self._transform = Affine2D().scale(0.5)

0 commit comments

Comments
 (0)