Skip to content

Commit 20a88f8

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 5977ca6 commit 20a88f8

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

lib/matplotlib/markers.py

+15-13
Original file line numberDiff line numberDiff line change
@@ -509,14 +509,12 @@ def _set_square(self):
509509
if not self._half_fill():
510510
self._path = Path.unit_rectangle()
511511
else:
512-
# Build a bottom filled square out of two rectangles, one filled.
513-
self._path = Path([[0.0, 0.0], [1.0, 0.0], [1.0, 0.5],
514-
[0.0, 0.5], [0.0, 0.0]])
515-
self._alt_path = Path([[0.0, 0.5], [1.0, 0.5], [1.0, 1.0],
516-
[0.0, 1.0], [0.0, 0.5]])
517-
rotate = {'bottom': 0, 'right': 90, 'top': 180, 'left': 270}[fs]
518-
self._transform.rotate_deg(rotate)
519-
self._alt_transform = self._transform
512+
self._path = self._alt_path = Path( # Half-square.
513+
[[0.0, 0.0], [1.0, 0.0], [1.0, 0.5], [0.0, 0.5], [0.0, 0.0]],
514+
closed=True)
515+
self._transform.rotate_deg(
516+
{'bottom': 0, 'right': 90, 'top': 180, 'left': 270}[fs])
517+
self._alt_transform = self._transform.frozen().rotate_deg(180)
520518

521519
self._joinstyle = 'miter'
522520

@@ -527,16 +525,20 @@ def _set_diamond(self):
527525
if not self._half_fill():
528526
self._path = Path.unit_rectangle()
529527
else:
530-
self._path = Path([[0, 0], [1, 0], [1, 1], [0, 0]])
531-
self._alt_path = Path([[0, 0], [0, 1], [1, 1], [0, 0]])
532-
rotate = {'right': 0, 'top': 90, 'left': 180, 'bottom': 270}[fs]
533-
self._transform.rotate_deg(rotate)
534-
self._alt_transform = self._transform
528+
eps = 1e-3 # Don't let the miter joins protrude.
529+
self._path = self._alt_path = Path(
530+
[[eps, eps], [eps, 0], [1, 0], [1, 1-eps], [1-eps, 1-eps],
531+
[eps, eps]], closed=True)
532+
self._transform.rotate_deg(
533+
{'right': 0, 'top': 90, 'left': 180, 'bottom': 270}[fs])
534+
self._alt_transform = self._transform.frozen().rotate_deg(180)
535535
self._joinstyle = 'miter'
536536

537537
def _set_thin_diamond(self):
538538
self._set_diamond()
539539
self._transform.scale(0.6, 1.0)
540+
if self._alt_transform:
541+
self._alt_transform.scale(0.6, 1.0)
540542

541543
def _set_pentagon(self):
542544
self._transform = Affine2D().scale(0.5)

0 commit comments

Comments
 (0)