Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1e9cfd6

Browse files
author
Steve Chaplin
committed
SC
svn path=/trunk/matplotlib/; revision=1463
1 parent de53136 commit 1e9cfd6

2 files changed

Lines changed: 30 additions & 28 deletions

File tree

lib/matplotlib/backend_bases.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,11 @@ def draw_line(self, gc, x1, y1, x2, y2):
169169
"""
170170
raise NotImplementedError
171171

172-
def draw_lines(self, gc, x, y):
172+
def draw_lines(self, gc, x, y, transform=None):
173173
"""
174174
x and y are equal length arrays, draw lines connecting each
175175
point in x, y
176176
"""
177-
178177
raise NotImplementedError
179178

180179
def draw_point(self, gc, x, y):

lib/matplotlib/backends/backend_cairo.py

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ def draw_arc(self, gc, rgbFace, x, y, width, height, angle1, angle2):
127127

128128

129129
def draw_image(self, x, y, im, origin, bbox):
130+
# bbox - not currently used
130131
if _debug: print '%s.%s()' % (self.__class__.__name__, _fn_name())
131132

132133
if numx.which[0] == "numarray":
@@ -139,10 +140,8 @@ def draw_image(self, x, y, im, origin, bbox):
139140
"draw_image()")
140141
return
141142

142-
# bbox - not currently used
143-
flipud = origin=='lower' # not currently used
144-
145-
#rows, cols, s = im.as_str(flipud) # gtk method, for RGBA
143+
#flipud = origin=='lower' # gtk method (uses RGBA)
144+
#rows, cols, s = im.as_str(flipud)
146145
rows, cols, buf = im.buffer_argb32() # ARGB32, but colors still wrong
147146
X = numx.fromstring (buf, numx.UInt8)
148147
X.shape = rows, cols, 4
@@ -151,6 +150,7 @@ def draw_image(self, x, y, im, origin, bbox):
151150
ctx = cairo.Context (self.surface)
152151
surface = cairo.ImageSurface.create_for_array (X)
153152
ctx.set_source_surface (surface, x, y)
153+
ctx.paint()
154154

155155

156156
def draw_line(self, gc, x1, y1, x2, y2):
@@ -316,7 +316,8 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle):
316316
return
317317

318318
if not HAVE_CAIRO_NUMPY:
319-
warnings.warn("cairo.numpy module required for _draw_mathtext()")
319+
warnings.warn("cairo with Numeric support is required for "
320+
"_draw_mathtext()")
320321
return
321322

322323
size = prop.get_size_in_points()
@@ -354,10 +355,10 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle):
354355
pa[:,:,3] = Xs
355356

356357
# works for numpy pa, not a numarray pa
357-
surface = cairo.numpy.surface_create_for_array(pa)
358-
gc.ctx.translate (x,y)
359-
gc.ctx.show_surface (surface, imw, imh)
360-
# should really restore state before translate?
358+
surface = cairo.ImageSurface.create_for_array (pa)
359+
gc.ctx.set_source_surface (surface, x, y)
360+
gc.ctx.paint()
361+
#gc.ctx.show_surface (surface, imw, imh)
361362

362363

363364
def flipy(self):
@@ -523,7 +524,8 @@ def new_figure_manager(num, *args, **kwargs): # called by backends/__init__.py
523524

524525
def print_figure_fn(figure, filename, dpi=150, facecolor='w', edgecolor='w',
525526
orientation='portrait'):
526-
if _debug: print '%s.%s()' % (self.__class__.__name__, _fn_name())
527+
#if _debug: print '%s.%s()' % (self.__class__.__name__, _fn_name())
528+
if _debug: print _fn_name()
527529

528530
# settings for printing
529531
figure.dpi.set(dpi)
@@ -550,8 +552,9 @@ def print_figure_fn(figure, filename, dpi=150, facecolor='w', edgecolor='w',
550552

551553
#if ext == 'png': _save_png (figure, fileObject)
552554
if ext == 'png': _save_png (figure, filename)
553-
else: _save_ps_pdf (figure, fileObject, ext,
554-
orientation)
555+
#else: _save_ps_pdf (figure, fileObject, ext,
556+
# orientation)
557+
else: _save_ps_pdf (figure, filename, ext, orientation)
555558
#fileObject.close()
556559

557560
elif ext in ('eps', 'svg'): # backend_svg/ps
@@ -567,41 +570,41 @@ def print_figure_fn(figure, filename, dpi=150, facecolor='w', edgecolor='w',
567570
(ext, ', '.join(IMAGE_FORMAT)))
568571

569572

570-
def _save_png (figure, fileObject):
573+
def _save_png (figure, filename):
571574
width, height = figure.get_width_height()
572575
width, height = int(width), int(height)
573576

574577
surface = cairo.ImageSurface (cairo.FORMAT_ARGB32, width, height)
575-
ctx = cairo.Context(surface)
578+
ctx = cairo.Context (surface)
576579

577580
renderer = RendererCairo (figure.dpi)
578-
renderer._set_width_height(width, height)
581+
renderer._set_width_height (width, height)
579582
renderer.surface = ctx.get_target()
580-
figure.draw(renderer)
581-
surface.write_to_png(fileObject)
583+
figure.draw (renderer)
584+
surface.write_to_png (filename)
582585

583586

584-
def _save_ps_pdf (figure, fileObject, ext, orientation):
587+
def _save_ps_pdf (figure, filename, ext, orientation):
585588
# Cairo produces PostScript Level 3
586589
# 'ggv' can't read cairo ps files, but 'gv' can
587590

588-
ppi = 200.0
591+
ppi = 200.0 # not currently used
589592
#figure.dpi.set(72)
590593
figure.dpi.set(96) # Cairo uses 96 dpi
591594

592595
w_in, h_in = figure.get_size_inches()
593596
width, height = figure.get_width_height()
594597

595-
ctx = cairo.Context()
596-
597598
if orientation == 'landscape':
598599
w_in, h_in = h_in, w_in
600+
# TODO - change width, height
599601

600602
if ext == 'ps':
601-
ctx.set_target_ps (fileObject, w_in, h_in, ppi, ppi)
603+
surface = cairo.PSSurface (filename, width, height)
602604
else: # pdf
603-
ctx.set_target_pdf (fileObject, w_in, h_in, ppi, ppi)
604-
605+
surface = cairo.PDFSurface (filename, width, height)
606+
ctx = cairo.Context (surface)
607+
605608
if orientation == 'landscape':
606609
ctx.rotate(numx.pi/2)
607610
ctx.translate(0, -height)
@@ -614,7 +617,7 @@ def _save_ps_pdf (figure, fileObject, ext, orientation):
614617

615618
renderer = RendererCairo (figure.dpi)
616619
renderer._set_width_height(width, height)
617-
renderer.surface = ctx.target_surface
620+
renderer.surface = ctx.get_target()
618621
figure.draw(renderer)
619622

620623
show_fig_border = False # for testing figure orientation and scaling
@@ -626,7 +629,7 @@ def _save_ps_pdf (figure, fileObject, ext, orientation):
626629
ctx.stroke()
627630
ctx.move_to(30,30)
628631
ctx.select_font_face ('sans-serif')
629-
ctx.scale_font(20)
632+
ctx.set_font_size(20)
630633
ctx.show_text('Origin corner')
631634

632635
ctx.show_page()

0 commit comments

Comments
 (0)