Beispiel #1
0
    def open_figure(self, fig, props):
        """
        Begin commands for a particular figure.

        Parameters
        ----------
        fig : matplotlib.Figure
            The Figure which will contain the ensuing axes and elements
        props : dictionary
            The dictionary of figure properties
        """
        self.canvas = PlotCanvas()
    def open_figure(self, fig, props):
        """
        Begin commands for a particular figure.

        Parameters
        ----------
        fig : matplotlib.Figure
            The Figure which will contain the ensuing axes and elements
        props : dictionary
            The dictionary of figure properties
        """
        self.canvas = PlotCanvas()
Beispiel #3
0
    def create_widgets(self):
        '''create widgets on main window'''
        self.label_ts_m = QLabel("Transmission spectrum of material", self)
        self.label_ts_m.move(10, 10)
        self.textbox_ts_m = PathTextBox(self)
        self.textbox_ts_m.setFixedWidth(400)
        self.textbox_ts_m.move(10, 30)

        self.label_bg_m = QLabel("Back ground spectrum of material", self)
        self.label_bg_m.move(10, 60)
        self.textbox_bg_m = PathTextBox(self)
        self.textbox_bg_m.setFixedWidth(400)
        self.textbox_bg_m.move(10, 80)

        self.label_ts_r = QLabel("Transmission spectrum of reference", self)
        self.label_ts_r.move(10, 110)
        self.textbox_ts_r = PathTextBox(self)
        self.textbox_ts_r.setFixedWidth(400)
        self.textbox_ts_r.move(10, 130)

        self.label_bg_r = QLabel("Back ground spectrum of reference", self)
        self.label_bg_r.move(10, 160)
        self.textbox_bg_r = PathTextBox(self)
        self.textbox_bg_r.setFixedWidth(400)
        self.textbox_bg_r.move(10, 180)

        self.pbutton_calc = QPushButton("calc", self)
        self.pbutton_calc.move(10, 210)
        self.pbutton_calc.clicked.connect(self.go_calc)

        self.plot_canvas = PlotCanvas(self, 3, 2.5)
        self.plot_canvas.move(420, 0)

        self.pbutton_save = QPushButton("save", self)
        self.pbutton_save.move(130, 210)
        self.pbutton_save.clicked.connect(self.save_fig)
            self._program[n] = v
            
        self._program['tr_scale'] = self._parent.panzoom.scale[:2]
            
        self._program['u_dash_atlas'] = gloo.Texture2D(self._collec.da._data)
        width, height = self.width, self.height
        self._program['u_scale'] = width//2, height//2
        self._program['u_proj'] = orthographic( -width//2, width//2, 
                                                -height//2, height//2, -1, +1 )
        
        self._program.draw('triangles', indices=self.index)



if __name__ == '__main__':
    ax = PlotCanvas(size=(600,600))
    
    
    x = np.linspace(-1., 1., 1000)
    y = .25*np.sin(15*x)
    vertices1 = np.c_[x,y]
    vertices2 = np.c_[np.cos(3*x)*.5, np.sin(3*x)*.5]

    
    ax.line = LineAggVisual(paths=[vertices1, vertices2], style=[
        dict(color=(1., 0., 0., 1.)),
        dict(color=(0., 1., 0., 1.)),
    ])
    ax.show()

Beispiel #5
0
class MainWidget(QWidget):

    def __init__(self):
        super().__init__()
        self.resize(720, 250)
        self.move(100, 100)
        self.setWindowTitle('calc_absorbance')
        self.create_widgets()
        self.show()

    def create_widgets(self):
        '''create widgets on main window'''
        self.label_ts_m = QLabel("Transmission spectrum of material", self)
        self.label_ts_m.move(10, 10)
        self.textbox_ts_m = PathTextBox(self)
        self.textbox_ts_m.setFixedWidth(400)
        self.textbox_ts_m.move(10, 30)

        self.label_bg_m = QLabel("Back ground spectrum of material", self)
        self.label_bg_m.move(10, 60)
        self.textbox_bg_m = PathTextBox(self)
        self.textbox_bg_m.setFixedWidth(400)
        self.textbox_bg_m.move(10, 80)

        self.label_ts_r = QLabel("Transmission spectrum of reference", self)
        self.label_ts_r.move(10, 110)
        self.textbox_ts_r = PathTextBox(self)
        self.textbox_ts_r.setFixedWidth(400)
        self.textbox_ts_r.move(10, 130)

        self.label_bg_r = QLabel("Back ground spectrum of reference", self)
        self.label_bg_r.move(10, 160)
        self.textbox_bg_r = PathTextBox(self)
        self.textbox_bg_r.setFixedWidth(400)
        self.textbox_bg_r.move(10, 180)

        self.pbutton_calc = QPushButton("calc", self)
        self.pbutton_calc.move(10, 210)
        self.pbutton_calc.clicked.connect(self.go_calc)

        self.plot_canvas = PlotCanvas(self, 3, 2.5)
        self.plot_canvas.move(420, 0)

        self.pbutton_save = QPushButton("save", self)
        self.pbutton_save.move(130, 210)
        self.pbutton_save.clicked.connect(self.save_fig)

    def go_calc(self):
        file_path = [self.textbox_ts_m.text(), self.textbox_bg_m.text(
        ), self.textbox_ts_r.text(), self.textbox_bg_r.text()]
        for path in file_path:
            if path == '':
                self.message_box = QMessageBox.information(
                    self, "", "file open error", QMessageBox.Close)
                return
        self.result_list = calc_abs(file_path)
        self.plot_canvas.plot(self.result_list)

    def save_fig(self):
        from pathlib import Path
        file_name, _ = QFileDialog.getSaveFileName(self)
        if len(file_name) == 0:
            return
        file_name = str(Path(file_name).with_suffix(".png"))
        self.plot_canvas.fig.savefig(file_name)

        output_csv = open(str(Path(file_name).with_suffix(".csv")), 'w')
        try:
            np.savetxt(str(Path(file_name).with_suffix(".csv")), self.result_list, delimiter=",")
        except:
            self.message_box = QMessageBox.information(
                self, "", "file save error", QMessageBox.Close)
Beispiel #6
0
class VispyRenderer(Renderer):
    def open_figure(self, fig, props):
        """
        Begin commands for a particular figure.

        Parameters
        ----------
        fig : matplotlib.Figure
            The Figure which will contain the ensuing axes and elements
        props : dictionary
            The dictionary of figure properties
        """
        self.canvas = PlotCanvas()

    def close_figure(self, fig):
        """
        Finish commands for a particular figure.

        Parameters
        ----------
        fig : matplotlib.Figure
            The figure which is finished being drawn.
        """
        pass

    def open_axes(self, ax, props):
        """
        Begin commands for a particular axes.

        Parameters
        ----------
        ax : matplotlib.Axes
            The Axes which will contain the ensuing axes and elements
        props : dictionary
            The dictionary of axes properties
        """
        pass

    def close_axes(self, ax):
        """
        Finish commands for a particular axes.

        Parameters
        ----------
        ax : matplotlib.Axes
            The Axes which is finished being drawn.
        """
        pass

    def open_legend(self, legend, props):
        """
        Beging commands for a particular legend.

        Parameters
        ----------
        legend : matplotlib.legend.Legend
                The Legend that will contain the ensuing elements
        props : dictionary
                The dictionary of legend properties
        """
        pass

    def close_legend(self, legend):
        """
        Finish commands for a particular legend.

        Parameters
        ----------
        legend : matplotlib.legend.Legend
                The Legend which is finished being drawn
        """
        pass

    def draw_markers(self, data, coordinates, style, label, mplobj=None):
        """
        Draw a set of markers. By default, this is done by repeatedly
        calling draw_path(), but renderers should generally overload
        this method to provide a more efficient implementation.

        In matplotlib, markers are created using the plt.plot() command.

        Parameters
        ----------
        data : array_like
            A shape (N, 2) array of datapoints.
        coordinates : string
            A string code, which should be either 'data' for data coordinates,
            or 'figure' for figure (pixel) coordinates.
        style : dictionary
            a dictionary specifying the appearance of the markers.
        mplobj : matplotlib object
            the matplotlib plot element which generated this marker collection
        """

        pos = data.astype(np.float32)
        n = pos.shape[0]

        # TODO: uniform instead
        color = np.tile(_string_to_rgb(style['facecolor']),
                        (n, 1)).astype(np.float32)

        # TODO: uniform instead
        size = np.ones(n, np.float32) * style['markersize']

        # TODO: marker style, linewidth, linecolor, etc.
        # TODO: take 'coordinates' into account

        self.canvas.add_visual(label,
                               MarkerVisual(pos=pos, color=color, size=size))

    def draw_path(self,
                  data,
                  coordinates,
                  pathcodes,
                  style,
                  offset=None,
                  offset_coordinates="data",
                  mplobj=None):
        """
        Draw a path.

        In matplotlib, paths are created by filled regions, histograms,
        contour plots, patches, etc.

        Parameters
        ----------
        data : array_like
            A shape (N, 2) array of datapoints.
        coordinates : string
            A string code, which should be either 'data' for data coordinates,
            'figure' for figure (pixel) coordinates, or "points" for raw
            point coordinates (useful in conjunction with offsets, below).
        pathcodes : list
            A list of single-character SVG pathcodes associated with the data.
            Path codes are one of ['M', 'm', 'L', 'l', 'Q', 'q', 'T', 't',
                                   'S', 's', 'C', 'c', 'Z', 'z']
            See the SVG specification for details.  Note that some path codes
            consume more than one datapoint (while 'Z' consumes none), so
            in general, the length of the pathcodes list will not be the same
            as that of the data array.
        style : dictionary
            a dictionary specifying the appearance of the line.
        offset : list (optional)
            the (x, y) offset of the path. If not given, no offset will
            be used.
        offset_coordinates : string (optional)
            A string code, which should be either 'data' for data coordinates,
            or 'figure' for figure (pixel) coordinates.
        mplobj : matplotlib object
            the matplotlib plot element which generated this path
        """
        pos = data.astype(np.float32)
        n = pos.shape[0]

        color = np.array(_string_to_rgb(style['edgecolor']), dtype=np.float32)

        self.canvas.add_visual('line' + randstr(),
                               LineVisual(pos=pos, color=color))

    def draw_path_collection(self,
                             paths,
                             path_coordinates,
                             path_transforms,
                             offsets,
                             offset_coordinates,
                             offset_order,
                             styles,
                             mplobj=None):
        """
        Draw a collection of paths. The paths, offsets, and styles are all
        iterables, and the number of paths is max(len(paths), len(offsets)).

        By default, this is implemented via multiple calls to the draw_path()
        function. For efficiency, Renderers may choose to customize this
        implementation.

        Examples of path collections created by matplotlib are scatter plots,
        histograms, contour plots, and many others.

        Parameters
        ----------
        paths : list
            list of tuples, where each tuple has two elements:
            (data, pathcodes).  See draw_path() for a description of these.
        path_coordinates: string
            the coordinates code for the paths, which should be either
            'data' for data coordinates, or 'figure' for figure (pixel)
            coordinates.
        path_transforms: array_like
            an array of shape (*, 3, 3), giving a series of 2D Affine
            transforms for the paths. These encode translations, rotations,
            and scalings in the standard way.
        offsets: array_like
            An array of offsets of shape (N, 2)
        offset_coordinates : string
            the coordinates code for the offsets, which should be either
            'data' for data coordinates, or 'figure' for figure (pixel)
            coordinates.
        offset_order : string
            either "before" or "after". This specifies whether the offset
            is applied before the path transform, or after.  The matplotlib
            backend equivalent is "before"->"data", "after"->"screen".
        styles: dictionary
            A dictionary in which each value is a list of length N, containing
            the style(s) for the paths.
        mplobj : matplotlib object
            the matplotlib plot element which generated this collection
        """
        print "path collec"
Beispiel #7
0
        # WARNING/TODO: put the different sets of uniforms and put them in attributes instead
        for n, v in self._U[0].iteritems():
            self._program[n] = v

        self._program['tr_scale'] = self._parent.panzoom.scale[:2]

        self._program['u_dash_atlas'] = gloo.Texture2D(self._collec.da._data)
        width, height = self.width, self.height
        self._program['u_scale'] = width // 2, height // 2
        self._program['u_proj'] = orthographic(-width // 2, width // 2,
                                               -height // 2, height // 2, -1,
                                               +1)

        self._program.draw('triangles', indices=self.index)


if __name__ == '__main__':
    ax = PlotCanvas(size=(600, 600))

    x = np.linspace(-1., 1., 1000)
    y = .25 * np.sin(15 * x)
    vertices1 = np.c_[x, y]
    vertices2 = np.c_[np.cos(3 * x) * .5, np.sin(3 * x) * .5]

    ax.line = LineAggVisual(paths=[vertices1, vertices2],
                            style=[
                                dict(color=(1., 0., 0., 1.)),
                                dict(color=(0., 1., 0., 1.)),
                            ])
    ax.show()
class VispyRenderer(Renderer):
    def open_figure(self, fig, props):
        """
        Begin commands for a particular figure.

        Parameters
        ----------
        fig : matplotlib.Figure
            The Figure which will contain the ensuing axes and elements
        props : dictionary
            The dictionary of figure properties
        """
        self.canvas = PlotCanvas()

    def close_figure(self, fig):
        """
        Finish commands for a particular figure.

        Parameters
        ----------
        fig : matplotlib.Figure
            The figure which is finished being drawn.
        """
        pass

    def open_axes(self, ax, props):
        """
        Begin commands for a particular axes.

        Parameters
        ----------
        ax : matplotlib.Axes
            The Axes which will contain the ensuing axes and elements
        props : dictionary
            The dictionary of axes properties
        """
        pass

    def close_axes(self, ax):
        """
        Finish commands for a particular axes.

        Parameters
        ----------
        ax : matplotlib.Axes
            The Axes which is finished being drawn.
        """
        pass

    def open_legend(self, legend, props):
        """
        Beging commands for a particular legend.

        Parameters
        ----------
        legend : matplotlib.legend.Legend
                The Legend that will contain the ensuing elements
        props : dictionary
                The dictionary of legend properties
        """
        pass

    def close_legend(self, legend):
        """
        Finish commands for a particular legend.

        Parameters
        ----------
        legend : matplotlib.legend.Legend
                The Legend which is finished being drawn
        """
        pass

    def draw_markers(self, data, coordinates, style, label, mplobj=None):
        """
        Draw a set of markers. By default, this is done by repeatedly
        calling draw_path(), but renderers should generally overload
        this method to provide a more efficient implementation.

        In matplotlib, markers are created using the plt.plot() command.

        Parameters
        ----------
        data : array_like
            A shape (N, 2) array of datapoints.
        coordinates : string
            A string code, which should be either 'data' for data coordinates,
            or 'figure' for figure (pixel) coordinates.
        style : dictionary
            a dictionary specifying the appearance of the markers.
        mplobj : matplotlib object
            the matplotlib plot element which generated this marker collection
        """
        
        pos = data.astype(np.float32)
        n = pos.shape[0]
        
        # TODO: uniform instead
        color = np.tile(_string_to_rgb(style['facecolor']), (n, 1)).astype(np.float32)
        
        # TODO: uniform instead
        size = np.ones(n, np.float32) * style['markersize']
        
        # TODO: marker style, linewidth, linecolor, etc.
        # TODO: take 'coordinates' into account
        
        self.canvas.add_visual(label, 
            MarkerVisual(pos=pos, color=color, size=size))

    def draw_path(self, data, coordinates, pathcodes, style,
                  offset=None, offset_coordinates="data", mplobj=None):
        """
        Draw a path.

        In matplotlib, paths are created by filled regions, histograms,
        contour plots, patches, etc.

        Parameters
        ----------
        data : array_like
            A shape (N, 2) array of datapoints.
        coordinates : string
            A string code, which should be either 'data' for data coordinates,
            'figure' for figure (pixel) coordinates, or "points" for raw
            point coordinates (useful in conjunction with offsets, below).
        pathcodes : list
            A list of single-character SVG pathcodes associated with the data.
            Path codes are one of ['M', 'm', 'L', 'l', 'Q', 'q', 'T', 't',
                                   'S', 's', 'C', 'c', 'Z', 'z']
            See the SVG specification for details.  Note that some path codes
            consume more than one datapoint (while 'Z' consumes none), so
            in general, the length of the pathcodes list will not be the same
            as that of the data array.
        style : dictionary
            a dictionary specifying the appearance of the line.
        offset : list (optional)
            the (x, y) offset of the path. If not given, no offset will
            be used.
        offset_coordinates : string (optional)
            A string code, which should be either 'data' for data coordinates,
            or 'figure' for figure (pixel) coordinates.
        mplobj : matplotlib object
            the matplotlib plot element which generated this path
        """
        pos = data.astype(np.float32)
        n = pos.shape[0]
        
        color = np.array(_string_to_rgb(style['edgecolor']), dtype=np.float32)
        
        self.canvas.add_visual('line'+randstr(), 
            LineVisual(pos=pos, color=color))
        
    def draw_path_collection(self, paths, path_coordinates, path_transforms,
                             offsets, offset_coordinates, offset_order,
                             styles, mplobj=None):
        """
        Draw a collection of paths. The paths, offsets, and styles are all
        iterables, and the number of paths is max(len(paths), len(offsets)).

        By default, this is implemented via multiple calls to the draw_path()
        function. For efficiency, Renderers may choose to customize this
        implementation.

        Examples of path collections created by matplotlib are scatter plots,
        histograms, contour plots, and many others.

        Parameters
        ----------
        paths : list
            list of tuples, where each tuple has two elements:
            (data, pathcodes).  See draw_path() for a description of these.
        path_coordinates: string
            the coordinates code for the paths, which should be either
            'data' for data coordinates, or 'figure' for figure (pixel)
            coordinates.
        path_transforms: array_like
            an array of shape (*, 3, 3), giving a series of 2D Affine
            transforms for the paths. These encode translations, rotations,
            and scalings in the standard way.
        offsets: array_like
            An array of offsets of shape (N, 2)
        offset_coordinates : string
            the coordinates code for the offsets, which should be either
            'data' for data coordinates, or 'figure' for figure (pixel)
            coordinates.
        offset_order : string
            either "before" or "after". This specifies whether the offset
            is applied before the path transform, or after.  The matplotlib
            backend equivalent is "before"->"data", "after"->"screen".
        styles: dictionary
            A dictionary in which each value is a list of length N, containing
            the style(s) for the paths.
        mplobj : matplotlib object
            the matplotlib plot element which generated this collection
        """
        print "path collec"