8000 SC 2005/03/05 · matplotlib/matplotlib@73bd926 · GitHub
[go: up one dir, main page]

Skip to content

Commit 73bd926

Browse files
author
Steve Chaplin
committed
SC 2005/03/05
svn path=/trunk/matplotlib/; revision=1045
1 parent ad45d16 commit 73bd926

File tree

2 files changed

+228
-153
lines changed

2 files changed

+228
-153
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 131 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
"""
2-
Abstract base classes definine the primitives that renderers and
2+
Abstract base classes define the primitives that renderers and
33
graphics contexts must implement to serve as a matplotlib backend
44
"""
55

66
from __future__ import division
77
import sys
88

9-
from matplotlib import verbose
109
from cbook import is_string_like, enumerate, strip_math, Stack
1110
from colors import colorConverter
1211
from numerix import array, sqrt, pi, log, asarray, ones, Float
@@ -53,24 +52,22 @@ def points_to_pixels(self, points):
5352
points to pixels = points * pixels_per_inch/72.0 * dpi/72.0
5453
"""
5554
return points
56-
5755

5856
def get_text_extent(self, text):
5957
"""
6058
Get the text extent in window coords
6159
"""
6260
return lbwh_to_bbox(0,0,1,1) # your values here
6361

64-
6562
def draw_arc(self, gcEdge, rgbFace, x, y, width, height, angle1, angle2):
6663
"""
6764
Draw an arc using GraphicsContext instance gcEdge, centered at x,y,
6865
with width and height and angles from 0.0 to 360.0
6966
7067
If the color rgbFace is not None, fill the arc with it.
7168
"""
72-
pass # derived must override
73-
69+
raise NotImplementedError
70+
7471
def draw_image(self, x, y, im, origin, bbox):
7572
"""
7673
Draw the Image instance into the current axes; x is the
@@ -84,25 +81,21 @@ def draw_image(self, x, y, im, origin, bbox):
8481
bbox is a matplotlib.transforms.BBox instance for clipping, or
8582
None
8683
"""
87-
print >>sys.stderr, 'This backend does not yet support images'
88-
89-
def draw_line(self, gc, x1, y1, x2, y2):
90-
"""
91-
Draw a single line from x1,y1 to x2,y2
92-
"""
93-
pass # derived must override
84+
raise NotImplementedError
9485

9586
def _draw_marker(self, gc, path, x, y, trans):
9687
"""
9788
This method is currently underscore hidden because the
9889
draw_markers method is being used as a sentinel for newstyle
9990
backend drawing
91+
92+
path - a list of path elements, see matplotlib.paths
10093
101-
Draw the marker specified in path with graphics context gx at
94+
Draw the marker specified in path with graphics context gc at
10295
each of the locations in arrays x and y. trans is a
10396
matplotlib.transforms.Transformation instance used to
10497
transform x and y to display coords. It consists of an
105-
optional ) nonlinear component and an affine. You can access
98+
optional nonlinear component and an affine. You can access
10699
these two components as
107100
108101
if transform.need_nonlinear():
@@ -113,6 +106,106 @@ def _draw_marker(self, gc, path, x, y, trans):
113106
"""
114107
pass
115108

109+
def draw_line_collection(self, segments, transform, clipbox,
110+
colors, linewidths, linestyle, antialiaseds,
111+
offsets, transOffset):
112+
"""
113+
This is a function for optimized line drawing. If you need to
114+
draw many line segments with similar properties, it is faster
115+
to avoid the overhead of all the object creation etc. The
116+
lack of total configurability is compensated for with
117+
efficiency. Hence we don't use a GC and many of the line
118+
props it supports. See matplotlib.collections for more
119+
details
120+
121+
sements is a sequence of ( line0, line1, line2), where linen =
122+
(x0, y0), (x1, y1), ... (xm, ym). Each line can be a
123+
different length
124+
125+
transform is used to Transform the lines
126+
127+
clipbox is a xmin, ymin, width, height clip rect
128+
129+
colors is a tuple of RGBA tuples
130+
131+
linewidths is a tuple of linewidths
132+
133+
linestyle is an (offset, onoffseq) tuple or None,None for solid
134+
135+
antialiseds is a tuple of ones or zeros indicating whether the
136+
segment should be aa or not
137+
138+
offsets, if not None, is a list of x,y offsets to translate
139+
the lines by after transoff is used to transform the offset
140+
coords
141+
142+
This function is intended to be overridden by the backend
143+
level in extension code for backends that want fast line
144+
collection drawing. Here is is implemented using native
145+
backend calls and may be slow
146+
"""
147+
148+
gc = self.new_gc()
149+
150+
i = 0
151+
Nc = len(colors)
152+
Nlw = len(linewidths)
153+
154+
Naa = len(antialiaseds)
155+
156+
usingOffsets = offsets is not None
157+
Noffsets = 0
158+
Nsegments = len(segments)
159+
if usingOffsets:
160+
Noffsets = len(offsets)
161+
162+
N = max(Noffsets, Nsegments)
163+
164+
gc.set_clip_rectangle(clipbox.get_bounds())
165+
166+
if linestyle[0] is not None:
167+
offset, seq = linestyle
168+
gc.set_dashes( offset, seq )
169+
170+
for i in xrange(N):
171+
x, y = zip(*segments[i % Nsegments])
172+
x, y = transform.numerix_x_y(array(x), array(y))
173+
174+
color = colors[i % Nc]
175+
rgb = color[0], color[1], color[2]
176+
alpha = color[-1]
177+
178+
gc.set_foreground( rgb, isRGB=True)
179+
gc.set_alpha( alpha )
180+
gc.set_linewidth( linewidths[i % Nlw] )
181+
182+
gc.set_antialiased( antialiaseds[i % Naa] )
183+
if usingOffsets:
184+
xo, yo = transOffset.xy_tup(offsets[i % Noffsets])
185+
x += xo
186+
y += yo
187+
self.draw_lines(gc, x, y)
188+
i += 1
189+
190+
def draw_line(self, gc, x1, y1, x2, y2):
191+
"""
192+
Draw a single line from x1,y1 to x2,y2
193+
"""
194+
raise NotImplementedError
195+
196+
def draw_lines(self, gc, x, y):
197+
"""
198+
x and y are equal length arrays, draw lines connecting each
199+
point in x, y
200+
"""
201+
raise NotImplementedError
202+
203+
def draw_point(self, gc, x, y):
204+
"""
205+
Draw a single point at x,y
206+
"""
207+
raise NotImplementedError
208+
116209
def draw_poly_collection(
117210
self, verts, transform, clipbox, facecolors, edgecolors,
118211
linewidths, antialiaseds, offsets, transOffset):
@@ -144,7 +237,6 @@ def draw_poly_collection(
144237
if clipbox is not None: gc.set_clip_rectangle(clipbox.get_bounds())
145238

146239
for i in xrange(N):
147-
148240

149241
rf,gf,bf,af = facecolors[i % Nface]
150242
re,ge,be,ae = edgecolors[i % Nedge]
@@ -167,6 +259,25 @@ def draw_poly_collection(
167259

168260
self.draw_polygon(gc, rgbFace, tverts)
169261

262+
def draw_polygon(self, gc, rgbFace, points):
263+
"""
264+
Draw a polygon using the GraphicsContext instance gc.
265+
points is a len vertices tuple, each element
266+
giving the x,y coords a vertex
267+
268+
If the color rgbFace is not None, fill the polygon with it
269+
"""
270+
raise NotImplementedError
271+
272+
def draw_rectangle(self, gcEdge, rgbFace, x, y, width, height):
273+
"""
274+
Draw a non-filled rectangle using the GraphicsContext instance gcEdge,
275+
with lower left at x,y with width and height.
276+
277+
If rgbFace is not None, fill the rectangle with it.
278+
"""
279+
raise NotImplementedError
280+
170281
def draw_regpoly_collection(
171282
self, clipbox, offsets, transOffset, verts, sizes,
172283
facecolors, edgecolors, linewidths, antialiaseds):
@@ -223,140 +334,24 @@ def draw_regpoly_collection(
223334
gc.set_antialiased( antialiaseds[i % Naa] )
224335
#print 'verts', zip(thisxverts, thisyverts)
225336
self.draw_polygon(gc, rgbFace, zip(thisxverts, thisyverts))
226-
227-
228-
229-
230-
def draw_line_collection(self, segments, transform, clipbox,
231-
colors, linewidths, linestyle, antialiaseds,
232-
offsets, transOffset):
233-
"""
234-
This is a function for optimized line drawing. If you need to
235-
draw many line segments with similar properties, it is faster
236-
to avoid the overhead of all the object creation etc. The
237-
lack of total configurability is compensated for with
238-
efficiency. Hence we don't use a GC and many of the line
239-
props it supports. See matplotlib.collections for more
240-
details
241-
242-
sements is a sequence of ( line0, line1, line2), where linen =
243-
(x0, y0), (x1, y1), ... (xm, ym). Each line can be a
244-
different length
245-
246-
transform is used to Transform the lines
247-
248-
clipbox i 1241 s a xmin, ymin, width, height clip rect
249337

250-
colors is a tuple of RGBA tuples
251-
252-
linewidths is a tuple of linewidths
253-
254-
linestyle is an (offset, onoffseq) tuple or None,None for solid
255-
256-
antialiseds is a tuple of ones or zeros indicating whether the
257-
segment should be aa or not
258-
259-
offsets, if not None, is a list of x,y offsets to translate
260-
the lines by after transoff is used to transform the offset
261-
coords
262-
263-
This function is intended to be overridden by the backend
264-
level in extension code for backends that want fast line
265-
collection drawing. Here is is implemented using native
266-
backend calls and may be slow
267-
"""
268-
269-
gc = self.new_gc()
270-
271-
i = 0
272-
Nc = len(colors)
273-
Nlw = len(linewidths)
274-
275-
Naa = len(antialiaseds)
276-
277-
usingOffsets = offsets is not None
278-
Noffsets = 0
279-
Nsegments = len(segments)
280-
if usingOffsets:
281-
Noffsets = len(offsets)
282-
283-
N = max(Noffsets, Nsegments)
284-
285-
gc.set_clip_rectangle(clipbox.get_bounds())
286-
287-
if linestyle[0] is not None:
288-
offset, seq = linestyle
289-
gc.set_dashes( offset, seq )
290-
291-
for i in xrange(N):
292-
x, y = zip(*segments[i % Nsegments])
293-
x, y = transform.numerix_x_y(array(x), array(y))
294-
295-
color = colors[i % Nc]
296-
rgb = color[0], color[1], color[2]
297-
alpha = color[-1]
298-
299-
gc.set_foreground( rgb, isRGB=True)
300-
gc.set_alpha( alpha )
301-
gc.set_linewidth( linewidths[i % Nlw] )
302-
303-
gc.set_antialiased( antialiaseds[i % Naa] )
304-
if usingOffsets:
305-
xo, yo = transOffset.xy_tup(offsets[i % Noffsets])
306-
x += xo
307-
y += yo
308-
self.draw_lines(gc, x, y)
309-
i += 1
310-
311-
def draw_lines(self, gc, x, y):
312-
"""
313-
x and y are equal length arrays, draw lines connecting each
314-
point in x, y
315-
"""
316-
pass # derived must override
317338

318-
def draw_point(self, gc, x, y):
319-
"""
320-
Draw a single point at x,y
321-
"""
322-
pass # derived must override
323-
324-
def draw_polygon(self, gc, rgbFace, points):
325-
"""
326-
Draw a polygon using the GraphicsContext instance gc.
327-
points is a len vertices tuple, each element
328-
giving the x,y coords a vertex
329-
330-
If the color rgbFace is not None, fill the polygon with it
331-
"""
332-
pass # derived must override
333-
334-
def draw_rectangle(self, gcEdge, rgbFace, x, y, width, height):
335-
"""
336-
Draw a non-filled rectangle using the GraphicsContext instance gcEdge,
337-
with lower left at x,y with width and height.
338-
339-
If rgbFace is not None, fill the rectangle with it.
340-
"""
341-
pass # derived must override
342-
343-
def strip_math(self, s):
344-
return strip_math(s)
345-
346339
def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
347340
"""
348341
Draw the text.Text instance s at x,y (display coords) with font
349342
properties instance prop at angle in degrees
350343
"""
351-
pass
352-
344+
raise NotImplementedError
353345

354346
def new_gc(self):
355347
"""
356348
Return an instance of a GraphicsContextBase
357349
"""
358350
return GraphicsContextBase()
359351

352+
def strip_math(self, s):
353+
return strip_math(s)
354+
360355

361356
class GraphicsContextBase:
362357
"""An abstract base class that provides color, line styles, etc...
@@ -1317,4 +1312,3 @@ def zoom(self, *args):
13171312
self.mode = 'Zoom to rect mode'
13181313

13191314
self.set_message(self.mode)
1320-

0 commit comments

Comments
 (0)
0