Beispiel #1
0
    def plotRU(self, rangeX=None, rangeY=None, save=False, filename=""):
        if save and filename == "":
            self.add_line("ERROR: I need a valid file name")
            return

        if save and filename.split('.')[-1] != "png":
            self.add_line("ERROR: File must end in .png")
            return

        if len(self.morseList) > 0:
            plotData = ArrayPlotData(x=self.Rlist,
                                     y=self.Ulist,
                                     morse=self.morseList,
                                     eigX=[self.Rlist[0], self.Rlist[-1]])
        else:
            plotData = ArrayPlotData(x=self.Rlist, y=self.Ulist)

        for val in self.levelsToFind:
            if val < len(self.convergedValues):
                plotData.set_data(
                    "eig" + str(val),
                    [self.convergedValues[val], self.convergedValues[val]])

        plot = Plot(plotData)

        if len(self.morseList) > 0:
            plot.plot(("x", "morse"), type="line", color="red")

        for val in self.levelsToFind:
            if val < len(self.convergedValues):

                plot.plot(("eigX", "eig" + str(val)),
                          type="line",
                          color="green")

        plot.plot(("x", "y"), type="line", color="blue")
        plot.plot(("x", "y"), type="scatter", marker_size=1.0, color="blue")
        #
        plot.index_axis.title = "Separation (r0)"
        if (self.scaled):
            plot.value_axis.title = "Potential (Eh * 2 * mu)"
        else:
            plot.value_axis.title = "Potential (Eh)"

        if len(self.plotRangeX) != 0:
            plot.x_axis.mapper.range.low = self.plotRangeX[0]
            plot.x_axis.mapper.range.high = self.plotRangeX[1]
        if len(self.plotRangeY) != 0:
            plot.y_axis.mapper.range.low = self.plotRangeY[0]
            plot.y_axis.mapper.range.high = self.plotRangeY[1]
        if not save:
            self.plot = plot
        else:
            plot.outer_bounds = [800, 600]
            plot.do_layout(force=True)
            gc = PlotGraphicsContext((800, 600), dpi=72)
            gc.render_component(plot)
            gc.save(filename)
    def plotRU(self,rangeX=None, rangeY=None, save=False, filename=""):
        if save and filename == "":
            self.add_line("ERROR: I need a valid file name")
            return

        if save and filename.split('.')[-1] != "png":
            self.add_line("ERROR: File must end in .png")
            return

        if len(self.morseList) > 0:
            plotData = ArrayPlotData(x=self.Rlist, y=self.Ulist, morse=self.morseList, eigX=[self.Rlist[0], self.Rlist[-1]])
        else:
            plotData = ArrayPlotData(x=self.Rlist, y=self.Ulist)


        for val in self.levelsToFind:
            if val < len(self.convergedValues):
                plotData.set_data("eig"+str(val), [self.convergedValues[val], self.convergedValues[val]])

        plot = Plot(plotData)

        if len(self.morseList) > 0:
            plot.plot(("x","morse"), type = "line", color = "red")

        for val in self.levelsToFind:
            if val < len(self.convergedValues):

                plot.plot(("eigX","eig"+str(val)), type="line", color="green")

        plot.plot(("x","y"), type = "line", color = "blue")
        plot.plot(("x","y"), type = "scatter", marker_size = 1.0, color = "blue")
        #
        plot.index_axis.title = "Separation (r0)"
        if (self.scaled):
            plot.value_axis.title = "Potential (Eh * 2 * mu)"
        else:
            plot.value_axis.title = "Potential (Eh)"

        if len(self.plotRangeX) != 0:
            plot.x_axis.mapper.range.low = self.plotRangeX[0]
            plot.x_axis.mapper.range.high = self.plotRangeX[1]
        if len(self.plotRangeY) != 0:
            plot.y_axis.mapper.range.low = self.plotRangeY[0]
            plot.y_axis.mapper.range.high = self.plotRangeY[1]
        if not save:
            self.plot = plot
        else:
            plot.outer_bounds = [800,600]
            plot.do_layout(force=True)
            gc = PlotGraphicsContext((800,600), dpi = 72)
            gc.render_component(plot)
            gc.save(filename)
    def test_draw_border_simple(self):
        """ Borders should have the correct height and width.
        """
        size = (5, 5)
        container = Plot(padding=1, border_visible=True)
        container.outer_bounds = list(size)
        gc = PlotGraphicsContext(size)
        gc.render_component(container)

        desired = array(
            ((255, 255, 255, 255, 255, 255), (255, 0, 0, 0, 0, 255),
             (255, 0, 255, 255, 0, 255), (255, 0, 255, 255, 0, 255),
             (255, 0, 0, 0, 0, 255), (255, 255, 255, 255, 255, 255)))

        actual = gc.bmp_array[:, :, 0]
        self.assertRavelEqual(actual, desired)
Beispiel #4
0
    def test_draw_border_simple(self):
        """ Borders should have the correct height and width.
        """
        size = (5,5)
        container = Plot(padding=1, border_visible=True)
        container.outer_bounds = list(size)
        gc = PlotGraphicsContext(size)
        gc.render_component(container)

        desired = array(((255, 255, 255, 255, 255, 255),
                         (255, 255, 255, 255, 255, 255),
                         (255,   0,   0,   0, 255, 255),
                         (255,   0, 255,   0, 255, 255),
                         (255,   0,   0,   0, 255, 255),
                         (255, 255, 255, 255, 255, 255)))

        actual = gc.bmp_array[:,:,0]
        self.assertRavelEqual(actual, desired)
from app_common.chaco.plot_io import save_plot_to_file

from chaco.api import Plot, ArrayPlotData
from chaco.api import PlotGraphicsContext
from chaco.pdf_graphics_context import PdfPlotGraphicsContext
from chaco.tools.api import SaveTool

data = {"x": [1, 2, 3, 4, 5], "y": [1, 2, 3, 2, 1]}

plot = Plot(ArrayPlotData(**data))

plot.plot(("x", "y"), type="scatter", color="blue")

plot.padding = 20
plot.outer_bounds = (800, 600)
plot.do_layout(force=True)

gc = PlotGraphicsContext((800, 600), dpi=72)
gc.render_component(plot, container_coords=(10, 10))
gc.save("test1.PNG")

# save_plot_to_file(plot, "test1.PNG")
# save_plot_to_file(plot, "test2.PNG")

# gc = PlotGraphicsContext((800, 600), dpi=72)
# plot.draw(gc)
# gc.save("test1.JPG")

# gc = PdfPlotGraphicsContext(filename="test1.PDF",
#                             pagesize="letter",
#                             dest_box=(0.5, 0.5, -0.5, -0.5),