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)
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 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) )
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 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"), ])
def setup_image(self, i, j, win): p = ImagePlot(win, xlabel=self.xlabel, ylabel=self.ylabel, zlabel=self.zlabel, yreverse=self.yreverse) self.main_widget = p win.add_plot(i, j, p) for item in self.images+self.plots: if item in self.images: item.set_color_map(self.colormap) p.add_item(item) if self.legend_position is not None: p.add_item(make.legend(self.legend_position)) return p
def setup_plot(self, i, j, win): p = CurvePlot(win, xlabel=self.xlabel, ylabel=self.ylabel) self.main_widget = p win.add_plot(i, j, p) for item in self.plots: p.add_item(item) p.enable_used_axes() active_item = p.get_active_item(force=True) p.set_scales(self.xscale, self.yscale) active_item.unselect() if self.legend_position is not None: p.add_item(make.legend(self.legend_position)) return p
def setup_image(self, i, j, win): p = ImagePlot(win, xlabel=self.xlabel, ylabel=self.ylabel, zlabel=self.zlabel, yreverse=self.yreverse) self.main_widget = p win.add_plot(i, j, p) for item in self.images + self.plots: if item in self.images: item.set_color_map(self.colormap) p.add_item(item) if self.legend_position is not None: p.add_item(make.legend(self.legend_position)) return p
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()
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)
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"),] )
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)