Beispiel #1
0
def export_plot_png(parent):
    # PNG export is not functional in chaco
    # https://github.com/enthought/chaco/issues/295
    dlg = wx.FileDialog(parent, "Export plot as PNG",
                        parent.config.get_path("PNG"), "",
                        "PNG file (*.png)|*.png",
                        wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
    if dlg.ShowModal() == wx.ID_OK:
        path = dlg.GetPath().encode("utf-8")
        if not path.endswith(".png"):
            path += ".png"
        parent.config.set_path(os.path.dirname(path), "PNG")
        container = parent.PlotArea.mainplot.container

        # get inner_boundary
        p = container

        dpi = 600
        p.do_layout(force=True)
        gc = ca.PlotGraphicsContext(tuple(p.outer_bounds), dpi=dpi)

        # temporarily turn off the backbuffer for offscreen rendering
        use_backbuffer = p.use_backbuffer
        p.use_backbuffer = False
        p.draw(gc)
        #gc.render_component(p)

        gc.save(path)

        p.use_backbuffer = use_backbuffer
Beispiel #2
0
def main():
    # Now we create a canvas of the appropriate size and ask it to render
    # our component.  (If we wanted to display this plot in a window, we
    # would not need to create the graphics context ourselves; it would be
    # created for us by the window.)
    plot_gc = chaco.PlotGraphicsContext(myplot.outer_bounds)
    plot_gc.render_component(myplot)

    # Get the directory to save the image in
    print('Please enter a path in which to place generated plots.')
    print('Press <ENTER> to generate in the current directory.')
    path = input('Path: ').strip()
    path = os.path.expanduser(path)

    if len(path) > 0 and not os.path.exists(path):
        print('The given path does not exist.')
        sys.exit()

    # The file name to save the plot as
    file_name = "tutorial1.png"

    if not os.path.isabs(path):
        print('Creating image: ' + os.path.join(os.getcwd(), path, file_name))
    else:
        print('Creating image: ' + os.path.join(path, file_name))

    # Finally, we tell the graphics context to save itself to disk as an image.
    plot_gc.save(os.path.join(path, file_name))
Beispiel #3
0
 def export_image(self, fname, size=sz_plot_img):
     """Save plot as png image."""
     # self.outer_bounds = list(size)
     # self.do_layout(force=True)
     gc = _chaco.PlotGraphicsContext(self.outer_bounds)
     gc.render_component(self)
     gc.save(fname, file_format=None)