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

Skip to content

Commit 839463b

Browse files
committed
draw_lines, draw_markers updated to the new API. draw_markers is still
masked, needs testing. svn path=/trunk/matplotlib/; revision=1129
1 parent 68eb00a commit 839463b

1 file changed

Lines changed: 76 additions & 30 deletions

File tree

lib/matplotlib/backends/backend_ps.py

Lines changed: 76 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55

66
from __future__ import division
77
import sys, os, time
8+
def _fn_name(): return sys._getframe(1).f_code.co_name
9+
810
from cStringIO import StringIO
911
from matplotlib import verbose, __version__, rcParams
1012
from matplotlib._pylab_helpers import Gcf
13+
import matplotlib.agg as agg
1114
from matplotlib.afm import AFM
1215
from matplotlib.backend_bases import RendererBase, GraphicsContextBase,\
1316
FigureManagerBase, FigureCanvasBase
1417

15-
from matplotlib.cbook import is_string_like, reverse_dict
18+
from matplotlib.cbook import is_string_like, izip, reverse_dict
1619
from matplotlib.figure import Figure
1720

1821
from matplotlib.font_manager import fontManager
@@ -28,7 +31,7 @@
2831

2932
backend_version = 'Level II'
3033
defaultPaperSize = 8.5,11 # TODO: make this configurable
31-
debugPS = 0
34+
debugPS = 1
3235

3336

3437

@@ -296,18 +299,24 @@ def draw_line(self, gc, x0, y0, x1, y1):
296299
"""
297300
ps = '%1.3f %1.3f m %1.3f %1.3f l'%(x0, y0, x1, y1)
298301
self._draw_ps(ps, gc, None, "line")
299-
300-
def _draw_markers(self, gc, path, x, y, transform):
302+
303+
def _draw_markers(self, gc, path, rgbFace, x, y, transform):
301304
"""
302305
Draw the markers defined by path at each of the positions in x
303306
and y. path coordinates are points, x and y coords will be
304307
transformed by the transform
305308
"""
306-
if debugPS:
307-
self._pswriter.write("% markers\n")
309+
if debugPS: self._pswriter.write('% draw_markers \n')
310+
311+
if rgbFace:
312+
if rgbFace[0]==rgbFace[0] and rgbFace[0]==rgbFace[2]:
313+
ps_color = '%1.3f setgray\n' % rgbFace[0]
314+
else:
315+
ps_color = '%1.3f %1.3f %1.3f setrgbcolor\n' % rgbFace
308316

309317
if transform.need_nonlinear():
310318
x,y = transform.nonlinear_only_numerix(x, y)
319+
x, y = transform.numerix_x_y(x, y)
311320

312321
# the a,b,c,d,tx,ty affine which transforms x and y
313322
vec6 = transform.as_vec6_val()
@@ -316,29 +325,41 @@ def _draw_markers(self, gc, path, x, y, transform):
316325
# and then simply iterate over the x and y and call this
317326
# function at each position. Eg, this is the path that is
318327
# relative to each x and y offset.
319-
ps = []
320-
for p in path:
321-
code = p[0]
322-
if code==MOVETO:
323-
mx, my = p[1:]
324-
ps.append('%1.3f %1.3f m')
325-
elif code==LINETO:
326-
mx, my = p[1:]
327-
ps.append('%1.3f %1.3f l')
328-
elif code==ENDPOLY:
329-
fill = p[1]
330-
if fill: # we can get the fill color here
331-
rgba = p[2:]
332-
333-
vertfunc = 'some magic ps function that draws the marker relative to an x,y point'
334-
# the gc contains the stroke width and color as always
335-
for i in xrange(len(x)):
336-
# for large numbers of markers you may need to chunk the
337-
# output, eg dump the ps in 1000 marker batches
338-
thisx = x[i]
339-
thisy = y[i]
340-
# apply affine transform x and y to define marker center
341-
#draw_marker_here
328+
329+
# construct the generic marker command:
330+
ps_cmd = ['gsave']
331+
ps_cmd.append('newpath')
332+
ps_cmd.append('%1.3f %1.3f translate')
333+
while 1:
334+
code, xp, yp = path.vertex()
335+
if code == agg.path_cmd_stop:
336+
break
337+
elif code == agg.path_cmd_move_to:
338+
ps_cmd.append('%1.3f %1.3f m' % (xp,yp))
339+
elif code == agg.path_cmd_line_to:
340+
ps_cmd.append('%1.3f %1.3f l' % (xp,yp))
341+
elif code == agg.path_cmd_curve3:
342+
pass
343+
elif code == agg.path_cmd_curve4:
344+
pass
345+
elif code == agg.path_cmd_end_poly:
346+
ps_cmd.append('closepath' % (xp,yp))
347+
elif code == agg.path_cmd_mask:
348+
pass
349+
else: print code
350+
if rgbFace:
351+
ps_cmd.append('gsave')
352+
ps_cmd.append(ps_color)
353+
ps_cmd.append('fill')
354+
ps_cmd.append('grestore')
355+
ps_cmd.append('stroke')
356+
ps_cmd.append('grestore') # undo translate()
357+
ps = '\n'.join(ps_cmd)
358+
359+
# Now evaluate the marker command at each marker location:
360+
draw_ps = self._draw_ps
361+
for xp,yp in izip(x,y):
362+
draw_ps(ps % (xp,yp), gc, None)
342363

343364
def _draw_lines(self, gc, points):
344365
"""
@@ -348,8 +369,33 @@ def _draw_lines(self, gc, points):
348369
ps = ["%1.3f %1.3f m" % points[0]]
349370
ps.extend(["%1.3f %1.3f l" % point for point in points[1:] ])
350371
self._draw_ps("\n".join(ps), gc, None)
372+
373+
def draw_lines(self, gc, x, y, transform=None):
374+
"""
375+
x and y are equal length arrays, draw lines connecting each
376+
point in x, y
377+
"""
378+
if debugPS: self._pswriter.write('% draw_lines \n')
379+
380+
if transform:
381+
if transform.need_nonlinear():
382+
x, y = transform.nonlinear_only_numerix(x, y)
383+
x, y = transform.numerix_x_y(x, y)
384+
385+
start = 0
386+
end = 1000
387+
points = zip(x,y)
388+
while 1:
389+
to_draw = points[start:end]
390+
if not to_draw:
391+
break
392+
ps = ["%1.3f %1.3f m" % to_draw[0]]
393+
ps.extend(["%1.3f %1.3f l" % point for point in to_draw[1:]])
394+
self._draw_ps("\n".join(ps), gc, None)
395+
start = end
396+
end += 1000
351397

352-
def draw_lines(self, gc, x, y):
398+
def draw_lines_old(self, gc, x, y):
353399
"""
354400
x and y are equal length arrays, draw lines connecting each
355401
point in x, y

0 commit comments

Comments
 (0)