8000 Fix single pixel markers. The pixel shape is now optimized so it doe… · matplotlib/matplotlib@6fa0064 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6fa0064

Browse files
committed
Fix single pixel markers. The pixel shape is now optimized so it does the right thing in the Agg backend. For raster backends, linejoin and cap styles is now correctly passed to and used in the backend.
1 parent eb95530 commit 6fa0064

File tree

5 files changed

+90
-38
lines changed

5 files changed

+90
-38
lines changed

lib/matplotlib/backends/backend_pdf.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,10 +1187,10 @@ def writeImages(self):
11871187

11881188
img.flipud_out()
11891189

1190-
def markerObject(self, path, trans, fillp, lw):
1190+
def markerObject(self, path, trans, fillp, lw, joinstyle, capstyle):
11911191
"""Return name of a marker XObject representing the given path."""
11921192
pathops = self.pathOperations(path, trans, simplify=False)
1193-
key = (tuple(pathops), bool(fillp))
1193+
key = (tuple(pathops), bool(fillp), joinstyle, capstyle)
11941194
result = self.markers.get(key)
11951195
if result is None:
11961196
name = Name('M%d' % len(self.markers))
@@ -1204,12 +1204,14 @@ def markerObject(self, path, trans, fillp, lw):
12041204
return name
12051205

12061206
def writeMarkers(self):
1207-
for (pathops, fillp),(name, ob, bbox, lw) in self.markers.iteritems():
1207+
for (pathops, fillp, joinstyle, capstyle),(name, ob, bbox, lw) in self.markers.iteritems():
12081208
bbox = bbox.padded(lw * 0.5)
12091209
self.beginStream(
12101210
ob.id, None,
12111211
{'Type': Name('XObject'), 'Subtype': Name('Form'),
12121212
'BBox': list(bbox.extents) })
1213+
self.output(GraphicsContextPdf.joinstyles[joinstyle], Op.setlinejoin)
1214+
self.output(GraphicsContextPdf.capstyles[capstyle], Op.setlinecap)
12131215
self.output(*pathops)
12141216
if fillp:
12151217
self.output(Op.fill_stroke)
@@ -1402,7 +1404,7 @@ def draw_image(self, gc, x, y, im, dx=None, dy=None, transform=None):
14021404
h = 72.0*h/self.image_dpi
14031405
else:
14041406
h = dy
1405-
1407+
14061408
imob = self.file.imageObject(im)
14071409

14081410
if transform is None:
@@ -1416,7 +1418,7 @@ def draw_image(self, gc, x, y, im, dx=None, dy=None, transform=None):
14161418
tr1, tr2, tr3, tr4, tr5, tr6, Op.concat_matrix,
14171419
w, 0, 0, h, x, y, Op.concat_matrix,
14181420
imob, Op.use_xobject, Op.grestore)
1419-
1421+
14201422

14211423
def draw_path(self, gc, path, transform, rgbFace=None):
14221424
self.check_gc(gc, rgbFace)
@@ -1438,7 +1440,8 @@ def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None)
14381440

14391441
output = self.file.output
14401442
marker = self.file.markerObject(
1441-
marker_path, marker_trans, fillp, self.gc._linewidth)
1443+
marker_path, marker_trans, fillp, self.gc._linewidth,
1444+
gc.get_joinstyle(), gc.get_capstyle())
14421445

14431446
output(Op.gsave)
14441447
lastx, lasty = 0, 0

lib/matplotlib/backends/backend_ps.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def gs_exe(self):
7272
self._cached["gs_exe"] = gs_exe
7373
return gs_exe
7474

75-
75+
7676
@property
7777
def gs_version(self):
7878
"""
@@ -97,7 +97,7 @@ def supports_ps2write(self):
9797
True if the installed ghostscript supports ps2write device.
9898
"""
9999
return self.gs_version[0] >= 9
100-
100+
101101
ps_backend_helper = PsBackendHelper()
102102

103103
papersize = {'letter': (8.5,11),
@@ -582,6 +582,11 @@ def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None)
582582

583583
# construct the generic marker command:
584584
ps_cmd = ['/o {', 'gsave', 'newpath', 'translate'] # dont want the translate to be global
585+
jint = gc.get_joinstyle()
586+
ps_cmd.append('%d setlinejoin' % jint)
587+
cint = gc.get_capstyle()
588+
ps_cmd.append('%d setlinecap' % cint)
589+
585590
ps_cmd.append(self._convert_path(marker_path, marker_trans,
586591
simplify=False))
587592

lib/matplotlib/backends/backend_svg.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ def _write_hatches(self):
370370
writer.end('pattern')
371371
writer.end('defs')
372372

373-
def _get_style(self, gc, rgbFace):
373+
def _get_style_dict(self, gc, rgbFace):
374374
"""
375375
return the style string. style is generated from the
376376
GraphicsContext and rgbFace
@@ -403,7 +403,10 @@ def _get_style(self, gc, rgbFace):
403403
if gc.get_capstyle() != 'projecting':
404404
attrib['stroke-linecap'] = _capstyle_d[gc.get_capstyle()]
405405

406-
return generate_css(attrib)
406+
return attrib
407+
408+
def _get_style(self, gc, rgbFace):
409+
return generate_css(self._get_style_dict(gc, rgbFace))
407410

408411
def _get_clip(self, gc):
409412
cliprect = gc.get_clip_rectangle()
@@ -536,12 +539,18 @@ def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None)
536539
marker_path,
537540
marker_trans + Affine2D().scale(1.0, -1.0),
538541
simplify=False)
539-
dictkey = (path_data)
542+
style = self._get_style_dict(gc, rgbFace)
543+
dictkey = (path_data, generate_css(style))
540544
oid = self._markers.get(dictkey)
545+
for key in style.keys():
546+
if not key.startswith('stroke'):
547+
del style[key]
548+
style = generate_css(style)
549+
541550
if oid is None:
542551
oid = self._make_id('m', dictkey)
543552
writer.start('defs')
544-
writer.element('path', id=oid, d=path_data)
553+
writer.element('path', id=oid, d=path_data, style=style)
545554
writer.end('defs')
546555
self._markers[dictkey] = oid
547556

lib/matplotlib/lines.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,8 @@ def draw(self, renderer):
541541
if type(snap) == float:
542542
snap = renderer.points_to_pixels(self._markersize) >= snap
543543
gc.set_snap(snap)
544+
gc.set_joinstyle(marker.get_joinstyle())
545+
gc.set_capstyle(marker.get_capstyle())
544546
marker_path = marker.get_path()
545547
marker_trans = marker.get_transform()
546548
w = renderer.points_to_pixels(self._markersize)

0 commit comments

Comments
 (0)
0