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

Skip to content

Fix single pixel markers #695

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 29, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions lib/matplotlib/backends/backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1187,10 +1187,10 @@ def writeImages(self):

img.flipud_out()

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

def writeMarkers(self):
for (pathops, fillp),(name, ob, bbox, lw) in self.markers.iteritems():
for (pathops, fillp, joinstyle, capstyle),(name, ob, bbox, lw) in self.markers.iteritems():
bbox = bbox.padded(lw * 0.5)
self.beginStream(
ob.id, None,
{'Type': Name('XObject'), 'Subtype': Name('Form'),
'BBox': list(bbox.extents) })
self.output(GraphicsContextPdf.joinstyles[joinstyle], Op.setlinejoin)
self.output(GraphicsContextPdf.capstyles[capstyle], Op.setlinecap)
self.output(*pathops)
if fillp:
self.output(Op.fill_stroke)
Expand Down Expand Up @@ -1402,7 +1404,7 @@ def draw_image(self, gc, x, y, im, dx=None, dy=None, transform=None):
h = 72.0*h/self.image_dpi
else:
h = dy

imob = self.file.imageObject(im)

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


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

output = self.file.output
marker = self.file.markerObject(
marker_path, marker_trans, fillp, self.gc._linewidth)
marker_path, marker_trans, fillp, self.gc._linewidth,
gc.get_joinstyle(), gc.get_capstyle())

output(Op.gsave)
lastx, lasty = 0, 0
Expand Down
24 changes: 20 additions & 4 deletions lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def gs_exe(self):
self._cached["gs_exe"] = gs_exe
return gs_exe


@property
def gs_version(self):
"""
Expand All @@ -97,7 +97,7 @@ def supports_ps2write(self):
True if the installed ghostscript supports ps2write device.
"""
return self.gs_version[0] >= 9

ps_backend_helper = PsBackendHelper()

papersize = {'letter': (8.5,11),
Expand Down Expand Up @@ -582,13 +582,29 @@ def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None)

# construct the generic marker command:
ps_cmd = ['/o {', 'gsave', 'newpath', 'translate'] # dont want the translate to be global

lw = gc.get_linewidth()
stroke = lw != 0.0
if stroke:
ps_cmd.append('%.1f setlinewidth' % lw)
jint = gc.get_joinstyle()
ps_cmd.append('%d setlinejoin' % jint)
cint = gc.get_capstyle()
ps_cmd.append('%d setlinecap' % cint)

ps_cmd.append(self._convert_path(marker_path, marker_trans,
simplify=False))

if rgbFace:
ps_cmd.extend(['gsave', ps_color, 'fill', 'grestore'])
if stroke:
ps_cmd.append('gsave')
ps_cmd.extend([ps_color, 'fill'])
if stroke:
ps_cmd.append('grestore')

ps_cmd.extend(['stroke', 'grestore', '} bind def'])
if stroke:
ps_cmd.append('stroke')
ps_cmd.extend(['grestore', '} bind def'])

for vertices, code in path.iter_segments(trans, simplify=False):
if len(vertices):
Expand Down
17 changes: 13 additions & 4 deletions lib/matplotlib/backends/backend_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def _write_hatches(self):
writer.end('pattern')
writer.end('defs')

def _get_style(self, gc, rgbFace):
def _get_style_dict(self, gc, rgbFace):
"""
return the style string. style is generated from the
GraphicsContext and rgbFace
Expand Down Expand Up @@ -403,7 +403,10 @@ def _get_style(self, gc, rgbFace):
if gc.get_capstyle() != 'projecting':
attrib['stroke-linecap'] = _capstyle_d[gc.get_capstyle()]

return generate_css(attrib)
return attrib

def _get_style(self, gc, rgbFace):
return generate_css(self._get_style_dict(gc, rgbFace))

def _get_clip(self, gc):
cliprect = gc.get_clip_rectangle()
Expand Down Expand Up @@ -536,12 +539,18 @@ def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None)
marker_path,
marker_trans + Affine2D().scale(1.0, -1.0),
simplify=False)
dictkey = (path_data)
style = self._get_style_dict(gc, rgbFace)
dictkey = (path_data, generate_css(style))
oid = self._markers.get(dictkey)
for key in style.keys():
if not key.startswith('stroke'):
del style[key]
style = generate_css(style)

if oid is None:
oid = self._make_id('m', dictkey)
writer.start('defs')
writer.element('path', id=oid, d=path_data)
writer.element('path', id=oid, d=path_data, style=style)
writer.end('defs')
self._markers[dictkey] = oid

Expand Down
7 changes: 6 additions & 1 deletion lib/matplotlib/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,11 +541,16 @@ def draw(self, renderer):
if type(snap) == float:
snap = renderer.points_to_pixels(self._markersize) >= snap
gc.set_snap(snap)
gc.set_joinstyle(marker.get_joinstyle())
gc.set_capstyle(marker.get_capstyle())
marker_path = marker.get_path()
marker_trans = marker.get_transform()
w = renderer.points_to_pixels(self._markersize)
if marker.get_marker() != ',': # Don't scale for pixels
if marker.get_marker() != ',':
# Don't scale for pixels, and don't stroke them
marker_trans = marker_trans.scale(w)
else:
gc.set_linewidth(0)
renderer.draw_markers(
gc, marker_path, marker_trans, subsampled, affine.frozen(),
rgbFace)
Expand Down
Loading