8000 SC 2005/03/09 · matplotlib/matplotlib@8732b79 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8732b79

Browse files
author
Steve Chaplin
committed
SC 2005/03/09
svn path=/trunk/matplotlib/; revision=1052
1 parent 7b9eac2 commit 8732b79

File tree

3 files changed

+61
-45
lines changed

3 files changed

+61
-45
lines changed

CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
New entries should be added at the top
22

3+
2005-03-09 cbook.py: only use enumerate() (the python version) if the builtin
4+
version is not available.
5+
Add new function 'izip' which is set to itertools.izip if available
6+
and the python equivalent if not available. - SC
7+
38
2005-03-07 backend_gdk.py: remove PIXELS_PER_INCH from points_to_pixels(), but
49
still use it to adjust font sizes. This allows the GTK version of
510
line_styles.py to more closely match GTKAgg, previously the markers

lib/matplotlib/backends/backend_cairo.py

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ def _fn_name(): return sys._getframe(1).f_code.co_name
2929
import matplotlib.numerix as numerix
3030
from matplotlib.backend_bases import RendererBase, GraphicsContextBase,\
3131
FigureManagerBase, FigureCanvasBase
32-
from matplotlib.cbook import enumerate
32+
from matplotlib.cbook import enumerate, izip
3333
from matplotlib.figure import Figure
3434
from matplotlib.mathtext import math_parse_s_ft2font
35+
from matplotlib.path import STOP, MOVETO, LINETO, CURVE3, CURVE4, ENDPOLY
3536
from matplotlib.transforms import Bbox
3637

3738
import cairo
@@ -181,6 +182,13 @@ def draw_line(self, gc, x1, y1, x2, y2):
181182
#def draw_lines(self, gc, x, y):
182183
def draw_lines(self, gc, x, y, transform=None):
183184
if DEBUG: print 'backend_cairo.RendererCairo.%s()' % _fn_name()
185+
186+
# guessing what needs to be done
187+
if transform:
188+
if transform.need_nonlinear():
189+
x, y = transform.nonlinear_only_numerix(x, y)
190+
x, y = transform.numerix_x_y(x, y)
191+
184192
y = [self.height - y for y in y]
185193
points = zip(x,y)
186194
x, y = points.pop(0)
@@ -193,75 +201,60 @@ def draw_lines(self, gc, x, y, transform=None):
193201
ctx.stroke()
194202

195203

196-
#def draw_markers(self, gc, path, x, y, transform):
197-
def _draw_markers(self, gc, path, x, y, transform): # disable, not finished yet
204+
def draw_markers(self, gc, path, x, y, transform):
205+
#def _draw_markers(self, gc, path, x, y, transform): # disable, not finished yet
198206
"""
199207
Draw the markers defined by path at each of the positions in x
200208
and y. path coordinates are points, x and y coords will be
201209
transformed by the transform
202210
"""
203211
if DEBUG: print 'backend_cairo.RendererCairo.%s()' % _fn_name()
204-
from matplotlib.path import STOP, MOVETO, LINETO, CURVE3, CURVE4, ENDPOLY
205212

206213
if transform.need_nonlinear():
207214
x,y = transform.nonlinear_only_numerix(x, y)
215+
x, y = transform.numerix_x_y(x, y) # todo - use cairo transform
208216

209217
# the a,b,c,d,tx,ty affine which transforms x and y
210-
vec6 = transform.as_vec6_val()
211-
# this defines a single vertex. We need to define this as ps
212-
# function, properly stroked and filled with linewidth etc,
213-
# and then simply iterate over the x and y and call this
214-
# function at each position. Eg, this is the path that is
215-
# relative to each x and y offset.
218+
#vec6 = transform.as_vec6_val() # not used (yet)
216219

217220
ctx = gc.ctx
218221

219222
def draw_path():
220223
# could trace path just once, then save/restore() ?
221224
for p in path:
222225
code = p[0]
223-
if code==MOVETO:
224-
mx, my = p[1:]
225-
# ctx.move_to (mx, self.height - my)
226-
ctx.move_to (mx, my)
227-
elif code==LINETO:
228-
mx, my = p[1:]
229-
# ctx.line_to (mx, self.height - my)
230-
ctx.line_to (mx, my)
231-
elif code==ENDPOLY:
226+
if code == MOVETO:
227+
ctx.move_to (p[1], -p[2])
228+
elif code == LINETO:
229+
ctx.line_to (p[1], -p[2])
230+
elif code == ENDPOLY:
232231
ctx.close_path()
233232
# draw_marker
234233
fill = p[1]
235-
if fill: # we can get the fill color here
234+
if fill:
236235
#rgba = p[2:]
237-
rgb = p[2:5] # later - set alpha
236+
rgb = p[2:5]
238237
ctx.save()
239238
ctx.set_rgb_color (*rgb)
239+
# later - set alpha also?
240240
ctx.fill()
241241
ctx.restore()
242242

243-
ctx.stroke() # later stroke and/or fill, sel fill color
244-
break
243+
ctx.stroke()
244+
break # end of path
245245

246-
# the gc contains the stroke width and color as always
247-
for i in xrange(len(x)):
246+
for x,y in izip(x,y):
248247
# FIXME
249-
# 1) markers are upside down
250-
# 2) get line-dash working
251-
# -> cmp to plot w/o draw_markers()
252-
# need to translate points to pixels?
253-
# look to writing in a more efficient way
248+
# -> mail dev list noting new function
249+
# graph with crosses is not working
250+
# -> cmp to plot w/o draw_markers()
254251
# use Cairo transform
252+
# look to writing in a more efficient way
255253

256254
ctx.save()
257-
thisx, thisy = x[i], y[i]
258-
259-
# apply affine transform x and y to define marker center
260255
ctx.new_path()
261-
tx, ty = transform.xy_tup((thisx, thisy))
262-
ctx.translate(tx, self.height - ty)
256+
ctx.translate(x, self.height - y)
263257
draw_path()
264-
265258
ctx.restore() # wrap translate()
266259

267260

lib/matplotlib/cbook.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,33 @@ def __get_item__(self, i):
272272
return self.data[i % len(self.data)]
273273

274274

275-
276-
major, minor1, minor2, s, tmp = sys.version_info
277-
def enumerate(seq):
278-
for i in range(len(seq)):
279-
yield i, seq[i]
280-
281-
275+
# use enumerate builtin if available, else use python version
276+
try:
277+
import __builtin__
278+
enumerate = __builtin__.enumerate
279+
except:
280+
def enumerate(seq):
281+
"""Python equivalent to the enumerate builtin function
282+
enumerate() is new in Python 2.3
283+
"""
284+
for i in range(len(seq)):
285+
yield i, seq[i]
286+
287+
288+
# use itertools.izip if available, else use python version
289+
try:
290+
import itertools
291+
izip = itertools.izip
292+
except:
293+
def izip(*iterables):
294+
"""Python equivalent to itertools.izip
295+
itertools module - new in Python 2.3
296+
"""
297+
iterables = map(iter, iterables)
298+
while iterables:
299+
result = [i.next() for i in iterables]
300+
yield tuple(result)
301+
282302

283303
def get_split_ind(seq, N):
284304
"""seq is a list of words. Return the index into seq such that
@@ -542,5 +562,3 @@ def finddir(o, match, case=False):
542562
names = [(name.lower(), name) for name in dir(o) if is_string_like(name)]
543563
match = match.lower()
544564
return [orig for name, orig in names if name.find(match)>=0]
545-
546-

0 commit comments

Comments
 (0)
0