Example #1
0
def test():
    """Test"""
    # -- Create QApplication
    import plotpy
    _app = plotpy.qapplication()
    # --
    from numpy import linspace, sin
    x = linspace(-10, 10, 200)
    dy = x/100.
    y = sin(sin(sin(x)))    
    x2 = linspace(-10, 10, 20)
    y2 = sin(sin(sin(x2)))
    curve2 = make.curve(x2, y2, color="g", curvestyle="Sticks")
    curve2.setTitle("toto")
    plot(make.curve(x, y, color="b"),
         curve2,
         make.curve(x, sin(2*y), color="r"),
         make.merror(x, y/2, dy),
         make.label("Relative position <b>outside</b>",
                    (x[0], y[0]), (-10, -10), "BR"),
         make.label("Relative position <i>inside</i>",
                    (x[0], y[0]), (10, 10), "TL"),
         make.label("Absolute position", "R", (0, 0), "R"),
         make.legend("TR"),
         make.marker(position=(5., .8), label_cb=lambda x, y: "A = %.2f" % x,
                     markerstyle="|", movable=False)
         )
Example #2
0
def test():
    """Test"""
    # -- Create QApplication
    import plotpy
    _app = plotpy.qapplication()
    # --
    from numpy import linspace, sin
    x = linspace(-10, 10, 200)
    dy = x / 100.
    y = sin(sin(sin(x)))
    x2 = linspace(-10, 10, 20)
    y2 = sin(sin(sin(x2)))
    plot([
        make.curve(x, y, color="b"),
        make.label("Relative position <b>outside</b>", (x[0], y[0]),
                   (-10, -10), "BR"),
    ], [
        make.curve(x2, y2, color="g"),
    ], [
        make.curve(x, sin(2 * y), color="r"),
        make.label("Relative position <i>inside</i>", (x[0], y[0]),
                   (10, 10), "TL"),
    ], [
        make.merror(x, y / 2, dy),
        make.label("Absolute position", "R", (0, 0), "R"),
        make.legend("TR"),
    ])
Example #3
0
    def refresh(self, slider_value=None):
        """Refresh Fit Tool dialog box"""
        # Update button states
        enable = self.x is not None and self.y is not None \
                 and self.x.size > 0 and self.y.size > 0 \
                 and self.fitfunc is not None and self.fitparams is not None \
                 and len(self.fitparams) > 0
        for btn in self.button_list:
            btn.setEnabled(enable)

        if not enable:
            # Fit widget is not yet configured
            return

        fitargs, fitkwargs = self.get_fitfunc_arguments()
        yfit = self.fitfunc(self.x, [p.value for p in self.fitparams],
                            *fitargs, **fitkwargs)

        plot = self.get_plot()

        if self.legend is None:
            self.legend = make.legend(anchor=self.legend_anchor)
            plot.add_item(self.legend)

        if self.xrange is None:
            self.xrange = make.range(0., 1.)
            plot.add_item(self.xrange)
        self.xrange.set_range(self.autofit_prm.xmin, self.autofit_prm.xmax)
        self.xrange.setVisible(self.show_xrange)

        if self.data_curve is None:
            self.data_curve = make.curve([], [],
                                         _("Data"),
                                         color="b",
                                         linewidth=2)
            plot.add_item(self.data_curve)
        self.data_curve.set_data(self.x, self.y)

        if self.fit_curve is None:
            self.fit_curve = make.curve([], [],
                                        _("Fit"),
                                        color="r",
                                        linewidth=2)
            plot.add_item(self.fit_curve)
        self.fit_curve.set_data(self.x, yfit)

        plot.replot()
        plot.disable_autoscale()
Example #4
0
def build_items():
    x = np.linspace(-10, 10, 200)
    y = np.sin(np.sin(np.sin(x)))
    filename = osp.join(osp.dirname(__file__), "brain.png")
    items = [
        make.curve(x, y, color="b"),
        make.image(filename=filename),
        make.trimage(filename=filename),
        make.maskedimage(filename=filename,
                         colormap='gray',
                         show_mask=True,
                         xdata=[0, 40],
                         ydata=[0, 50]),
        make.label("Relative position <b>outside</b>", (x[0], y[0]),
                   (-10, -10), "BR"),
        make.label("Relative position <i>inside</i>", (x[0], y[0]), (10, 10),
                   "TL"),
        make.label("Absolute position", "R", (0, 0), "R"),
        make.legend("TR"),
        make.rectangle(-3, -0.8, -0.5, -1., "rc1"),
        make.segment(-3, -0.8, -0.5, -1., "se1"),
        make.ellipse(-10, 0.0, 0, 0, "el1"),
        make.annotated_rectangle(0.5, 0.8, 3, 1., "rc1", "tutu"),
        make.annotated_segment(-1, -1, 1, 1., "rc1", "tutu"),
        Axes((0, 0), (1, 0), (0, 1)),
        PolygonShape(
            np.array([[150., 330.], [270., 520.], [470., 480.], [520., 360.],
                      [460., 200.], [250., 240.]])),
    ]
    return items
def build_items():
    x = np.linspace(-10, 10, 200)
    y = np.sin(np.sin(np.sin(x)))
    filename = osp.join(osp.dirname(__file__), "brain.png")
    items = [ 
              make.curve(x, y, color="b"),
              make.image(filename=filename),
              make.trimage(filename=filename),
              make.maskedimage(filename=filename, colormap='gray',
                               show_mask=True, xdata=[0, 40], ydata=[0, 50]),
              make.label("Relative position <b>outside</b>",
                         (x[0], y[0]), (-10, -10), "BR"),
              make.label("Relative position <i>inside</i>",
                         (x[0], y[0]), (10, 10), "TL"),
              make.label("Absolute position", "R", (0, 0), "R"),
              make.legend("TR"),
              make.rectangle(-3, -0.8, -0.5, -1., "rc1"),
              make.segment(-3, -0.8, -0.5, -1., "se1"),
              make.ellipse(-10, 0.0, 0, 0, "el1"),
              make.annotated_rectangle(0.5, 0.8, 3, 1., "rc1", "tutu"),
              make.annotated_segment(-1, -1, 1, 1., "rc1", "tutu"),
              Axes( (0, 0), (1, 0), (0, 1) ),
              PolygonShape(np.array([[150., 330.],
                                     [270., 520.],
                                     [470., 480.],
                                     [520., 360.],
                                     [460., 200.],
                                     [250., 240.]])),
              ]
    return items
Example #6
0
def test():
    """Test"""
    # -- Create QApplication
    import plotpy
    _app = plotpy.qapplication()
    # --
    from numpy import linspace, sin, trapz
    x = linspace(-10, 10, 1000)
    y = sin(sin(sin(x)))

    curve = make.curve(x, y, "ab", "b")
    range = make.range(-2, 2)
    disp0 = make.range_info_label(range,
                                  'BR',
                                  "x = %.1f ± %.1f cm",
                                  title="Range infos")

    disp1 = make.computation(range, "BL", "trapz=%g", curve,
                             lambda x, y: trapz(y, x))

    disp2 = make.computations(range, "TL",
                              [(curve, "min=%.5f", lambda x, y: y.min()),
                               (curve, "max=%.5f", lambda x, y: y.max()),
                               (curve, "avg=%.5f", lambda x, y: y.mean())])
    legend = make.legend("TR")
    plot(curve, range, disp0, disp1, disp2, legend)
Example #7
0
    def refresh(self, slider_value=None):
        """Refresh Fit Tool dialog box"""
        # Update button states
        enable = self.x is not None and self.y is not None \
                 and self.x.size > 0 and self.y.size > 0 \
                 and self.fitfunc is not None and self.fitparams is not None \
                 and len(self.fitparams) > 0
        for btn in self.button_list:
            btn.setEnabled(enable)
            
        if not enable:
            # Fit widget is not yet configured
            return

        fitargs, fitkwargs = self.get_fitfunc_arguments()
        yfit = self.fitfunc(self.x, [p.value for p in self.fitparams],
                            *fitargs, **fitkwargs)
                            
        plot = self.get_plot()
        
        if self.legend is None:
            self.legend = make.legend(anchor=self.legend_anchor)
            plot.add_item(self.legend)
        
        if self.xrange is None:
            self.xrange = make.range(0., 1.)
            plot.add_item(self.xrange)
        self.xrange.set_range(self.autofit_prm.xmin, self.autofit_prm.xmax)
        self.xrange.setVisible(self.show_xrange)
        
        if self.data_curve is None:
            self.data_curve = make.curve([], [],
                                         _("Data"), color="b", linewidth=2)
            plot.add_item(self.data_curve)
        self.data_curve.set_data(self.x, self.y)
        
        if self.fit_curve is None:
            self.fit_curve = make.curve([], [],
                                        _("Fit"), color="r", linewidth=2)
            plot.add_item(self.fit_curve)
        self.fit_curve.set_data(self.x, yfit)
        
        plot.replot()
        plot.disable_autoscale()
Example #8
0
def hist2d(X, Y):
    win = ImageDialog(edit=True, toolbar=True,
                      wintitle="2-D Histogram X0=(0,1), X1=(-1,-1)")
    hist2d = make.histogram2D(X, Y, 200, 200)
    curve = make.curve(X[::50], Y[::50],
                       linestyle='', marker='+', title=_("Markers"))
    plot = win.get_plot()
    plot.set_aspect_ratio(lock=False)
    plot.set_antialiasing(False)
    plot.add_item(hist2d)
    plot.add_item(curve)
    plot.set_item_visible(curve, False)
    win.show()
    win.exec_()
Example #9
0
def test():
    """Test"""
    # -- Create QApplication
    import plotpy
    _app = plotpy.qapplication()
    # --
    from numpy import linspace, sin
    x = linspace(-10, 10, 200)
    dy = x/100.
    y = sin(sin(sin(x)))    
    x2 = linspace(-10, 10, 20)
    y2 = sin(sin(sin(x2)))
    plot([make.curve(x, y, color="b"),
          make.label("Relative position <b>outside</b>",
                     (x[0], y[0]), (-10, -10), "BR"),],
         [make.curve(x2, y2, color="g"),
          ],
         [make.curve(x, sin(2*y), color="r"),
          make.label("Relative position <i>inside</i>",
                     (x[0], y[0]), (10, 10), "TL"),],
         [make.merror(x, y/2, dy),
          make.label("Absolute position", "R", (0, 0), "R"),
          make.legend("TR"),]
         )
Example #10
0
 def setup_widget(self, title):
     #---Create the plot widget:
     self.plot = CurvePlot(self)
     self.curve_item = make.curve([], [], color='b')
     self.plot.add_item(self.curve_item)
     self.plot.set_antialiasing(True)
     #---
     
     button = QPushButton("Test filter: %s" % title)
     button.clicked.connect(self.process_data)
     vlayout = QVBoxLayout()
     vlayout.addWidget(self.plot)
     vlayout.addWidget(button)
     self.setLayout(vlayout)
     
     self.update_curve()
Example #11
0
    def setup_widget(self, title):
        #---Create the plot widget:
        self.plot = CurvePlot(self)
        self.curve_item = make.curve([], [], color='b')
        self.plot.add_item(self.curve_item)
        self.plot.set_antialiasing(True)
        #---

        button = QPushButton("Test filter: %s" % title)
        button.clicked.connect(self.process_data)
        vlayout = QVBoxLayout()
        vlayout.addWidget(self.plot)
        vlayout.addWidget(button)
        self.setLayout(vlayout)

        self.update_curve()
Example #12
0
def test():
    """Test"""
    # -- Create QApplication
    import plotpy
    _app = plotpy.qapplication()
    # --
    from numpy import linspace, sin
    x = linspace(-10, 10, 1000)+1
    y = sin(sin(sin(x)))+3

    curve = make.curve(x, y, "ab", "b")
    hcursor = make.hcursor(3.2, label='y = %.2f')
    vcursor = make.vcursor(7,  label='x = %.2f')
    vcursor2 = make.vcursor(-1,  label='NOT MOVABLE = %.2f', movable=False)
    xcursor = make.xcursor(-4, 2.5,  label='x = %.2f<br>y = %.2f')
    legend = make.legend("TR")
    plot(curve, hcursor, vcursor, vcursor2, xcursor, legend)
Example #13
0
def test():
    """Test"""
    # -- Create QApplication
    import plotpy
    _app = plotpy.qapplication()
    # --
    import numpy as np
    x = np.linspace(-10, 10, 200)
    y = x*np.exp(-x)
    item = make.curve(x, y, color="b")
    
    win = CurveDialog()
    plot = win.get_plot()
    plot.add_item(item)
    plot.set_axis_direction("left", True)
    plot.set_axis_direction("bottom", True)
    win.show()
    win.exec_()
Example #14
0
def hist2d(X, Y):
    win = ImageDialog(edit=True,
                      toolbar=True,
                      wintitle="2-D Histogram X0=(0,1), X1=(-1,-1)")
    hist2d = make.histogram2D(X, Y, 200, 200)
    curve = make.curve(X[::50],
                       Y[::50],
                       linestyle='',
                       marker='+',
                       title=_("Markers"))
    plot = win.get_plot()
    plot.set_aspect_ratio(lock=False)
    plot.set_antialiasing(False)
    plot.add_item(hist2d)
    plot.add_item(curve)
    plot.set_item_visible(curve, False)
    win.show()
    win.exec_()
Example #15
0
def test():
    """Test"""
    # -- Create QApplication
    import plotpy
    _app = plotpy.qapplication()
    # --
    import numpy as np
    x = np.linspace(-10, 10, 200)
    y = x * np.exp(-x)
    item = make.curve(x, y, color="b")

    win = CurveDialog()
    plot = win.get_plot()
    plot.add_item(item)
    plot.set_axis_direction("left", True)
    plot.set_axis_direction("bottom", True)
    win.show()
    win.exec_()
Example #16
0
def test():
    """Test"""
    # -- Create QApplication
    import plotpy
    _app = plotpy.qapplication()
    # --
    import numpy as np
    x = np.linspace(1, 10, 200)
    y = np.exp(-x)
    y[0] = 0
    item = make.curve(x, y, color="b")
    item = make.error(x, y, None, y * .23)

    win = CurveDialog()
    plot = win.get_plot()
    plot.set_axis_scale("left", "log")
    plot.set_axis_scale("bottom", "log")
    #    plot.set_axis_limits("left", 4.53999297625e-05, 22026.4657948)
    plot.add_item(item)
    win.show()
    win.exec_()
Example #17
0
def test():
    """Test"""
    # -- Create QApplication
    import plotpy
    _app = plotpy.qapplication()
    # --
    import numpy as np
    x = np.linspace(1, 10, 200)
    y = np.exp(-x)
    y[0] = 0
    item = make.curve(x, y, color="b")
    item = make.error(x, y, None, y*.23)
    
    win = CurveDialog()
    plot = win.get_plot()
    plot.set_axis_scale("left", "log")
    plot.set_axis_scale("bottom", "log")
#    plot.set_axis_limits("left", 4.53999297625e-05, 22026.4657948)
    plot.add_item(item)
    win.show()
    win.exec_()
Example #18
0
def test():
    """Test"""
    # -- Create QApplication
    import plotpy
    _app = plotpy.qapplication()
    # --
    from numpy import linspace, sin, trapz
    x = linspace(-10, 10, 1000)
    y = sin(sin(sin(x)))

    curve = make.curve(x, y, "ab", "b")
    range = make.range(-2, 2)
    disp0 = make.range_info_label(range, 'BR', "x = %.1f ± %.1f cm",
                                  title="Range infos")

    disp1 = make.computation(range, "BL", "trapz=%g",
                             curve, lambda x, y: trapz(y, x))

    disp2 = make.computations(range, "TL",
                              [(curve, "min=%.5f", lambda x, y: y.min()),
                               (curve, "max=%.5f", lambda x, y: y.max()),
                               (curve, "avg=%.5f", lambda x, y: y.mean())])
    legend = make.legend("TR")
    plot( curve, range, disp0, disp1, disp2, legend)