5
5
6
6
from __future__ import division
7
7
import sys , os , time
8
+ def _fn_name (): return sys ._getframe (1 ).f_code .co_name
9
+
8
10
from cStringIO import StringIO
9
11
from matplotlib import verbose , __version__ , rcParams
10
12
from matplotlib ._pylab_helpers import Gcf
13
+ import matplotlib .agg as agg
11
14
from matplotlib .afm import AFM
12
15
from matplotlib .backend_bases import RendererBase , GraphicsContextBase ,\
13
16
FigureManagerBase , FigureCanvasBase
14
17
15
- from matplotlib .cbook import is_string_like , reverse_dict
18
+ from matplotlib .cbook import is_string_like , izip , reverse_dict
16
19
from matplotlib .figure import Figure
17
20
18
21
from matplotlib .font_manager import fontManager
28
31
29
32
backend_version = 'Level II'
30
33
defaultPaperSize = 8.5 ,11 # TODO: make this configurable
31
- debugPS = 0
34
+ debugPS = 1
32
35
33
36
34
37
@@ -296,18 +299,24 @@ def draw_line(self, gc, x0, y0, x1, y1):
296
299
"""
297
300
ps = '%1.3f %1.3f m %1.3f %1.3f l' % (x0 , y0 , x1 , y1 )
298
301
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 ):
301
304
"""
302
305
Draw the markers defined by path at each of the positions in x
303
306
and y. path coordinates are points, x and y coords will be
304
307
transformed by the transform
305
308
"""
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
308
316
309
317
if transform .need_nonlinear ():
310
318
x ,y = transform .nonlinear_only_numerix (x , y )
319
+ x , y = transform .numerix_x_y (x , y )
311
320
312
321
# the a,b,c,d,tx,ty affine which transforms x and y
313
322
vec6 = transform .as_vec6_val ()
@@ -316,29 +325,41 @@ def _draw_markers(self, gc, path, x, y, transform):
316
325
# and then simply iterate over the x and y and call this
317
326
# function at each position. Eg, this is the path that is
318
327
# 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 )
342
363
343
364
def _draw_lines (self , gc , points ):
344
365
"""
@@ -348,8 +369,33 @@ def _draw_lines(self, gc, points):
348
369
ps = ["%1.3f %1.3f m" % points [0 ]]
349
370
ps .extend (["%1.3f %1.3f l" % point for point in points [1 :] ])
350
371
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
351
397
352
- def draw_lines (self , gc , x , y ):
398
+ def draw_lines_old (self , gc , x , y ):
353
399
"""
354
400
x and y are equal length arrays, draw lines connecting each
355
401
point in x, y
0 commit comments