@@ -81,15 +81,14 @@ def draw_line_collection(self, segments, transform, clipbox,
81
81
colors , linewidths , linestyle , antialiaseds ,
82
82
offsets , transOffset ):
83
83
"""
84
- This is a function for optimized line drawing. If you need to
85
- draw many line segments with similar properties, it is faster
86
- to avoid the overhead of all the object creation etc. The
87
- lack of total configurability is compensated for with
88
- efficiency. Hence we don't use a GC and many of the line
89
- props it supports. See matplotlib.collections for more
90
- details
91
-
92
- sements is a sequence of ( line0, line1, line2), where linen =
84
+ This is a function for optimized line drawing. If you need to draw
85
+ many line segments with similar properties, it is faster to avoid the
86
+ overhead of all the object creation etc. The lack of total
87
+ configurability is compensated for with efficiency. Hence we don't use
88
+ a GC and many of the line props it supports. See
89
+ matplotlib.collections for more details.
90
+
91
+ segments is a sequence of ( line0, line1, line2), where linen =
93
92
(x0, y0), (x1, y1), ... (xm, ym). Each line can be a
94
93
different length
95
94
@@ -100,63 +99,52 @@ def draw_line_collection(self, segments, transform, clipbox,
100
99
colors is a tuple of RGBA tuples
101
100
102
101
linewidths is a tuple of linewidths
102
+ *** really should be called 'dashes' not 'linestyle', since
103
+ we call gc.set_dashes() not gc.set_linestyle() ***
103
104
104
105
linestyle is an (offset, onoffseq) tuple or None,None for solid
105
106
106
107
antialiseds is a tuple of ones or zeros indicating whether the
107
108
segment should be aa or not
108
109
109
- offsets, if not None, is a list of x,y offsets to translate
110
- the lines by after transoff is used to transform the offset
111
- coords
110
+ offsets, if not None, is a list of x,y offsets to translate the lines
111
+ by after transform is used to transform the offset coords
112
112
113
- This function is intended to be overridden by the backend
114
- level in extension code for backends that want fast line
115
- collection drawing. Here is is implemented using native
116
- backend calls and may be slow
113
+ This function could be overridden in the backend to possibly implement
114
+ faster drawing, but it is already much faster than using draw_lines()
115
+ by itself.
117
116
"""
118
-
119
117
gc = self .new_gc ()
118
+ gc .set_clip_rectangle (clipbox .get_bounds ())
119
+ gc .set_dashes (* linestyle )
120
120
121
- i = 0
122
- Nc = len (colors )
123
- Nlw = len (linewidths )
124
-
125
- Naa = len (antialiaseds )
121
+ Nc = len (colors )
122
+ Nlw = len (linewidths )
123
+ Naa = len (antialiaseds )
124
+ Nsegments = len (segments )
126
125
127
126
usingOffsets = offsets is not None
128
- Noffsets = 0
129
- Nsegments = len (segments )
127
+ Noffsets = 0
130
128
if usingOffsets :
131
129
Noffsets = len (offsets )
132
130
133
- N = max (Noffsets , Nsegments )
134
-
135
- gc .set_clip_rectangle (clipbox .get_bounds ())
136
-
137
- if linestyle [0 ] is not None :
138
- offset , seq = linestyle
139
- gc .set_dashes ( offset , seq )
140
-
141
- for i in xrange (N ):
142
- x , y = zip (* segments [i % Nsegments ])
143
- x , y = transform .numerix_x_y (array (x ), array (y ))
144
-
131
+ for i in xrange (max (Noffsets , Nsegments )):
145
132
color = colors [i % Nc ]
146
- rgb = color [0 ], color [1 ], color [2 ]
133
+ rgb = color [0 ], color [1 ], color [2 ]
147
134
alpha = color [- 1 ]
148
135
149
- gc .set_foreground ( rgb , isRGB = True )
136
+ gc .set_foreground (rgb , isRGB = True )
150
137
gc .set_alpha ( alpha )
151
138
gc .set_linewidth ( linewidths [i % Nlw ] )
152
-
153
139
gc .set_antialiased ( antialiaseds [i % Naa ] )
140
+
141
+ x , y = zip (* segments [i % Nsegments ])
142
+ x , y = transform .numerix_x_y (array (x ), array (y ))
154
143
if usingOffsets :
155
144
xo , yo = transOffset .xy_tup (offsets [i % Noffsets ])
156
145
x += xo
157
146
y += yo
158
147
self .draw_lines (gc , x , y )
159
- i += 1
160
148
161
149
def draw_line (self , gc , x1 , y1 , x2 , y2 ):
162
150
"""
@@ -191,7 +179,6 @@ def draw_poly_collection(
191
179
linewidths are a sequence of linewidths
192
180
antialiaseds are a sequence of 0,1 integers whether to use aa
193
181
"""
194
-
195
182
Nface = len (facecolors )
196
183
Nedge = len (edgecolors )
197
184
Nlw = len (linewidths )
@@ -256,10 +243,10 @@ def draw_regpoly_collection(
256
243
"""
257
244
Draw a regular poly collection
258
245
259
- offsets is a sequence is x,y tuples and transOffset maps this
260
- to display coords
246
+ offsets - is a sequence is x,y tuples
247
+ transOffset - maps this to display coords
261
248
262
- verts are the vertices of the regular polygon at the origin
249
+ verts - are the vertices of the regular polygon at the origin
263
250
264
251
sizes are the area of the circle that circumscribes the
265
252
polygon in points^2
@@ -268,20 +255,20 @@ def draw_regpoly_collection(
268
255
linewidths are a sequence of linewidths
269
256
antialiaseds are a sequence of 0,1 integers whether to use aa
270
257
"""
258
+ gc = self .new_gc ()
259
+ if clipbox is not None :
260
+ gc .set_clip_rectangle (clipbox .get_bounds ())
261
F438
+
271
262
xverts , yverts = zip (* verts )
272
263
xverts = asarray (xverts )
273
264
yverts = asarray (yverts )
274
265
275
- Nface = len (facecolors )
276
- Nedge = len (edgecolors )
277
- Nlw = len (linewidths )
278
- Naa = len (antialiaseds )
266
+ Nface = len (facecolors )
267
+ Nedge = len (edgecolors )
268
+ Nlw = len (linewidths )
269
+ Naa = len (antialiaseds )
279
270
Nsizes = len (sizes )
280
271
281
-
282
- gc = self .new_gc ()
283
- if clipbox is not None : gc .set_clip_rectangle (clipbox .get_bounds ())
284
-
285
272
for i , loc in enumerate (offsets ):
286
273
xo ,yo = transOffset .xy_tup (loc )
287
274
#print 'xo, yo', loc, (xo, yo)
@@ -304,6 +291,7 @@ def draw_regpoly_collection(
304
291
gc .set_alpha ( alpha )
305
292
gc .set_linewidth ( linewidths [i % Nlw ] )
306
293
gc .set_antialiased ( antialiaseds [i % Naa ] )
294
+
307
295
#print 'verts', zip(thisxverts, thisyverts)
308
296
self .draw_polygon (gc , rgbFace , zip (thisxverts , thisyverts ))
309
297
@@ -327,7 +315,9 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
327
315
raise NotImplementedError
328
316
329
317
def flipy (self ):
330
- 'return true if y small numbers are top for renderer'
318
+ """return true if y small numbers are top for renderer
319
+ Is used for drawing text (text.py) and images (image.py) only
320
+ """
331
321
return True
332
322
333
323
def get_canvas_width_height (self ):
@@ -355,10 +345,13 @@ def new_gc(self):
355
345
356
346
def points_to_pixels (self , points ):
357
347
"""
358
- Convert points to display units (as a float).
359
- You need to override this function (unless your backend doesn't have
348
+ Convert points to display units
349
+ points - a float or a numerix array of float
350
+ return points converted to pixels
351
+
352
+ You need to override this function (unless your backend doesn't have a
360
353
dpi, eg, postscript or svg).
361
- Many imaging systems assume some value for pixels per inch.
354
+ Some imaging systems assume some value for pixels per inch.
362
355
points to pixels = points * pixels_per_inch/72.0 * dpi/72.0
363
356
"""
364
357
return points
@@ -494,9 +487,10 @@ def set_clip_rectangle(self, rectangle):
494
487
495
488
def set_dashes (self , dash_offset , dash_list ):
496
489
"""
497
- Set the dash style for the gc. dash offset is the offset
498
- (usually 0). Dash list specifies the on-off sequence as
499
- points
490
+ Set the dash style for the gc.
491
+ dash_offset is the offset (usually 0).
492
+ dash_list specifies the on-off sequence as points
493
+ (None, None) specifies a solid line
500
494
"""
501
495
self ._dashes = dash_offset , dash_list
502
496
@@ -541,13 +535,13 @@ def set_linestyle(self, style):
541
535
Set the linestyle to be one of ('solid', 'dashed', 'dashdot',
542
536
'dotted').
543
537
"""
544
- if style in ('solid' , 'dashed' , 'dashdot' , 'dotted' ):
545
- self ._linestyle = style
538
+ try :
546
539
offset , dashes = self .dashd [style ]
547
- self .set_dashes (offset , dashes )
548
- else :
549
- raise ValueError ('Unrecognized linestyle: Found %s' % style )
550
-
540
+ except :
541
+ raise ValueError ('Unrecognized linestyle: %s' % style )
542
+ self ._linestyle = style
543
+ self .set_dashes (offset , dashes )
544
+
551
545
552
546
class Event :
553
547
"""
0 commit comments