@@ -29,9 +29,10 @@ def _fn_name(): return sys._getframe(1).f_code.co_name
29
29
import matplotlib .numerix as numerix
30
30
from matplotlib .backend_bases import RendererBase , GraphicsContextBase ,\
31
31
FigureManagerBase , FigureCanvasBase
32
- from matplotlib .cbook import enumerate
32
+ from matplotlib .cbook import enumerate , izip
33
33
from matplotlib .figure import Figure
34
34
from matplotlib .mathtext import math_parse_s_ft2font
35
+ from matplotlib .path import STOP , MOVETO , LINETO , CURVE3 , CURVE4 , ENDPOLY
35
36
from matplotlib .transforms import Bbox
36
37
37
38
import cairo
@@ -181,6 +182,13 @@ def draw_line(self, gc, x1, y1, x2, y2):
181
182
#def draw_lines(self, gc, x, y):
182
183
def draw_lines (self , gc , x , y , transform = None ):
183
184
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
+
184
192
y = [self .height - y for y in y ]
185
193
points = zip (x ,y )
186
194
x , y = points .pop (0 )
@@ -193,75 +201,60 @@ def draw_lines(self, gc, x, y, transform=None):
193
201
ctx .stroke ()
194
202
195
203
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
198
206
"""
199
207
Draw the markers defined by path at each of the positions in x
200
208
and y. path coordinates are points, x and y coords will be
201
209
transformed by the transform
202
210
"""
203
211
if DEBUG : print 'backend_cairo.RendererCairo.%s()' % _fn_name ()
204
- from matplotlib .path import STOP , MOVETO , LINETO , CURVE3 , CURVE4 , ENDPOLY
205
212
206
213
if transform .need_nonlinear ():
207
214
x ,y = transform .nonlinear_only_numerix (x , y )
215
+ x , y = transform .numerix_x_y (x , y ) # todo - use cairo transform
208
216
209
217
# 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)
216
219
217
220
ctx = gc .ctx
218
221
219
222
def draw_path ():
220
223
# could trace path just once, then save/restore() ?
221
224
for p in path :
222
225
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 :
232
231
ctx .close_path ()
233
232
# draw_marker
234
233
fill = p [1 ]
235
- if fill : # we can get the fill color here
234
+ if fill :
236
235
#rgba = p[2:]
237
- rgb = p [2 :5 ] # later - set alpha
236
+ rgb = p [2 :5 ]
238
237
ctx .save ()
239
238
ctx .set_rgb_color (* rgb )
239
+ # later - set alpha also?
240
240
ctx .fill ()
241
241
ctx .restore ()
242
242
243
- ctx .stroke () # later stroke and/or fill, sel fill color
244
- break
243
+ ctx .stroke ()
244
+ break # end of path
245
245
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 ):
248
247
# 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()
254
251
# use Cairo transform
252
+ # look to writing in a more efficient way
255
253
256
254
ctx .save ()
257
- thisx , thisy = x [i ], y [i ]
258
-
259
- # apply affine transform x and y to define marker center
260
255
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 )
263
257
draw_path ()
264
-
265
258
ctx .restore () # wrap translate()
266
259
267
260
0 commit comments