8000 SC 2005/03/11 · matplotlib/matplotlib@aad3cfd · GitHub
[go: up one dir, main page]

Skip to content

Commit aad3cfd

Browse files
author
Steve Chaplin
committed
SC 2005/03/11
svn path=/trunk/matplotlib/; revision=1066
1 parent cb1b1f7 commit aad3cfd

File tree

1 file changed

+59
-65
lines changed

1 file changed

+59
-65
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 59 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,14 @@ def draw_line_collection(self, segments, transform, clipbox,
8181
colors, linewidths, linestyle, antialiaseds,
8282
offsets, transOffset):
8383
"""
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 =
9392
(x0, y0), (x1, y1), ... (xm, ym). Each line can be a
9493
different length
9594
@@ -100,63 +99,52 @@ def draw_line_collection(self, segments, transform, clipbox,
10099
colors is a tuple of RGBA tuples
101100
102101
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() ***
103104
104105
linestyle is an (offset, onoffseq) tuple or None,None for solid
105106
106107
antialiseds is a tuple of ones or zeros indicating whether the
107108
segment should be aa or not
108109
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
112112
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.
117116
"""
118-
119117
gc = self.new_gc()
118+
gc.set_clip_rectangle(clipbox.get_bounds())
119+
gc.set_dashes(*linestyle)
120120

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)
126125

127126
usingOffsets = offsets is not None
128-
Noffsets = 0
129-
Nsegments = len(segments)
127+
Noffsets = 0
130128
if usingOffsets:
131129
Noffsets = len(offsets)
132130

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)):
145132
color = colors[i % Nc]
146-
rgb = color[0], color[1], color[2]
133+
rgb = color[0], color[1], color[2]
147134
alpha = color[-1]
148135

149-
gc.set_foreground( rgb, isRGB=True)
136+
gc.set_foreground(rgb, isRGB=True)
150137
gc.set_alpha( alpha )
151138
gc.set_linewidth( linewidths[i % Nlw] )
152-
153139
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))
154143
if usingOffsets:
155144
xo, yo = transOffset.xy_tup(offsets[i % Noffsets])
156145
x += xo
157146
y += yo
158147
self.draw_lines(gc, x, y)
159-
i += 1
160148

161149
def draw_line(self, gc, x1, y1, x2, y2):
162150
"""
@@ -191,7 +179,6 @@ def draw_poly_collection(
191179
linewidths are a sequence of linewidths
192180
antialiaseds are a sequence of 0,1 integers whether to use aa
193181
"""
194-
195182
Nface = len(facecolors)
196183
Nedge = len(edgecolors)
197184
Nlw = len(linewidths)
@@ -256,10 +243,10 @@ def draw_regpoly_collection(
256243
"""
257244
Draw a regular poly collection
258245
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
261248
262-
verts are the vertices of the regular polygon at the origin
249+
verts - are the vertices of the regular polygon at the origin
263250
264251
sizes are the area of the circle that circumscribes the
265252
polygon in points^2
@@ -268,20 +255,20 @@ def draw_regpoly_collection(
268255
linewidths are a sequence of linewidths
269256
antialiaseds are a sequence of 0,1 integers whether to use aa
270257
"""
258+
gc = self.new_gc()
259+
if clipbox is not None:
260+
gc.set_clip_rectangle(clipbox.get_bounds())
261 F438 +
271262
xverts, yverts = zip(*verts)
272263
xverts = asarray(xverts)
273264
yverts = asarray(yverts)
274265

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)
279270
Nsizes = len(sizes)
280271

281-
282-
gc = self.new_gc()
283-
if clipbox is not None: gc.set_clip_rectangle(clipbox.get_bounds())
284-
285272
for i, loc in enumerate(offsets):
286273
xo,yo = transOffset.xy_tup(loc)
287274
#print 'xo, yo', loc, (xo, yo)
@@ -304,6 +291,7 @@ def draw_regpoly_collection(
304291
gc.set_alpha( alpha )
305292
gc.set_linewidth( linewidths[i % Nlw] )
306293
gc.set_antialiased( antialiaseds[i % Naa] )
294+
307295
#print 'verts', zip(thisxverts, thisyverts)
308296
self.draw_polygon(gc, rgbFace, zip(thisxverts, thisyverts))
309297

@@ -327,7 +315,9 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
327315
raise NotImplementedError
328316

329317
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+
"""
331321
return True
332322

333323
def get_canvas_width_height(self):
@@ -355,10 +345,13 @@ def new_gc(self):
355345

356346
def points_to_pixels(self, points):
357347
"""
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
360353
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.
362355
points to pixels = points * pixels_per_inch/72.0 * dpi/72.0
363356
"""
364357
return points
@@ -494,9 +487,10 @@ def set_clip_rectangle(self, rectangle):
494487

495488
def set_dashes(self, dash_offset, dash_list):
496489
"""
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
500494
"""
501495
self._dashes = dash_offset, dash_list
502496

@@ -541,13 +535,13 @@ def set_linestyle(self, style):
541535
Set the linestyle to be one of ('solid', 'dashed', 'dashdot',
542536
'dotted').
543537
"""
544-
if style in ('solid', 'dashed', 'dashdot', 'dotted'):
545-
self._linestyle = style
538+
try:
546539
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+
551545

552546
class Event:
553547
"""

0 commit comments

Comments
 (0)
0