def do_expose_event(self, event): cr = self.window.cairo_create() if not self.cached_contents: self.cached_contents = cr.get_target().create_similar(cairo.CONTENT_COLOR, self.allocation.width, self.allocation.height) renderer = RendererCairo(self.figure.dpi) renderer.set_width_height(self.allocation.width, self.allocation.height) renderer.set_ctx_from_surface(self.cached_contents) self.figure.draw(renderer) # event.region is not bound: http://bugzilla.gnome.org/show_bug.cgi?id=487158 # gdk_context = gtk.gdk.CairoContext(renderer.ctx) # gdk_context.region(event.region) # gdk_context.clip() cr.set_source_surface(self.cached_contents, 0, 0) cr.paint()
def make_histogram(self, data, show_axis=None, distance=True): color = colors.Category.CAT20C[0] matplotlib.rcParams.update({'font.size': 9.5}) figure = Figure(frameon=False, figsize=(4, 2), dpi=72, edgecolor=color) specs = matplotlib.gridspec.GridSpec(ncols=8, nrows=1, figure=figure) plot = figure.add_subplot(specs[0, 1:7]) plot.patch.set_alpha(1.0) adjust_spines(plot, ['left'], color) formatter = FormatStrFormatter('%g') plot.yaxis.set_major_formatter(formatter) plot.yaxis.set_major_locator(MaxNLocator(5)) if distance: plot.plot(data[:, 0], data[:, 1], lw=0.75) else: plot.vlines(data[:, 0], 0, data[:, 1]) plot.set_xlim(min(data[:, 0]), max(data[:, 0])) # Ask matplotlib to render the figure to a bitmap using the Agg backend canvas = FigureCanvasCairo(figure) width, height = canvas.get_width_height() renderer = RendererCairo(canvas.figure.dpi) renderer.set_width_height(width, height) self.plot_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) renderer.set_ctx_from_surface(self.plot_surface) canvas.figure.draw(renderer) self.show_histogram = True
def print_result(self, print_context, render=True): figure = Figure(facecolor='white', figsize=(6,4.5)) figure.set_dpi(72) # Don't draw the frame, please. figure.set_frameon(False) canvas = _PlotResultCanvas(figure) axes = figure.add_subplot(111) self._replay(axes) width, height = figure.bbox.width, figure.bbox.height if render: cr = print_context.get_cairo_context() renderer = RendererCairo(figure.dpi) renderer.set_width_height(width, height) if hasattr(renderer, 'gc'): # matplotlib-0.99 and newer renderer.gc.ctx = cr else: # matplotlib-0.98 # RendererCairo.new_gc() does a restore to get the context back # to its original state after changes cr.save() renderer.ctx = cr figure.draw(renderer) if not hasattr(renderer, 'gc'): # matplotlib-0.98 # Reverse the save() we did before drawing cr.restore() return height
def print_result(self, print_context, render=True): figure = Figure(facecolor='white', figsize=(6, 4.5)) figure.set_dpi(72) # Don't draw the frame, please. figure.set_frameon(False) canvas = _PlotResultCanvas(figure) axes = figure.add_subplot(111) self._replay(axes) width, height = figure.bbox.width, figure.bbox.height if render: cr = print_context.get_cairo_context() renderer = RendererCairo(figure.dpi) renderer.set_width_height(width, height) if hasattr(renderer, 'gc'): # matplotlib-0.99 and newer renderer.gc.ctx = cr else: # matplotlib-0.98 # RendererCairo.new_gc() does a restore to get the context back # to its original state after changes cr.save() renderer.ctx = cr figure.draw(renderer) if not hasattr(renderer, 'gc'): # matplotlib-0.98 # Reverse the save() we did before drawing cr.restore() return height
def do_expose_event(self, event): cr = self.window.cairo_create() if not self.cached_contents: self.cached_contents = cr.get_target().create_similar( cairo.CONTENT_COLOR, self.allocation.width, self.allocation.height) renderer = RendererCairo(self.figure.dpi) renderer.set_width_height(self.allocation.width, self.allocation.height) renderer.set_ctx_from_surface(self.cached_contents) self.figure.draw(renderer) # event.region is not bound: http://bugzilla.gnome.org/show_bug.cgi?id=487158 # gdk_context = gtk.gdk.CairoContext(renderer.ctx) # gdk_context.region(event.region) # gdk_context.clip() cr.set_source_surface(self.cached_contents, 0, 0) cr.paint()
def benu_draw(self, ctx): renderer = RendererCairo(self.figure.dpi) renderer.gc.ctx = ctx renderer.set_width_height (self.wpx, self.hpx) self.figure.draw (renderer)
def _renderer_init(self): """Override to use Cairo rather than GDK renderer""" if _debug: print '%s.%s()' % (self.__class__.__name__, _fn_name()) self._renderer = RendererCairo(self.figure.dpi)