コード例 #1
0
ファイル: plotwindow.py プロジェクト: AndrDm/nditoolbox-labs
 def add_toolbar(self):
     """Creates the matplotlib toolbar (zoom, pan/scroll, etc.)
     for the plot"""
     self.toolbar = NavigationToolbar2Wx(self.canvas)
     self.toolbar.Realize()
     if wx.Platform == '__WXMAC__':
         self.SetToolBar(self.toolbar)
     else:
         tw, th = self.toolbar.GetSizeTuple()
         fw, fh = self.canvas.GetSizeTuple()
         self.toolbar.SetSize(wx.Size(fw, th))
         self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND, 0)
     self.toolbar.update()
コード例 #2
0
    def __init__(self, parent, *args, **kwargs):
        super().__init__(parent, *args, **kwargs)

        self.figure = Figure()
        self.axes = self.figure.add_subplot(111)
        self.canvas = FigureCanvas(self, -1, self.figure)
        self.toolbar = NavigationToolbar2Wx(self.canvas)
        self.toolbar.Realize()

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
        sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
        self.SetSizer(sizer)
        self.Fit()
コード例 #3
0
    def __init__(self, parent, figure_width=12.0, figure_height=8.5):
        wx.Panel.__init__(self, parent, wx.ID_ANY)

        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(self.sizer)
        self.ctrl_sizer = wx.BoxSizer(wx.HORIZONTAL)
        self.fig = plt.figure(figsize=(figure_width, figure_height),
                              tight_layout=True,
                              frameon=False)
        self.fig.clf()
        self.linestyles = ["-", "--", ":", "-."]
        self.markers = ["^", "v", "+", "d", "o"]
        self.cmap = plt.cm.ScalarMappable(plt.Normalize(0, 1), "rainbow")
        self.canvas = FigureCanvas(self, -1, self.fig)
        self.axlist = []
        self.canvas.mpl_connect('motion_notify_event', self.UpdateCoords)
        self.Bind(EVT_DONE_PLOTTING, self.OnDonePlotting)
        self.plot_toolbar = NavigationToolbar2Wx(self.canvas)
        fw, th = self.plot_toolbar.GetSize().Get()
        self.plot_toolbar.SetSize(wx.Size(fw, th))
        self.plot_toolbar.Realize()
        self.ctrl_sizer.Add(self.plot_toolbar, 0, wx.ALL | \
                wx.ALIGN_CENTER_VERTICAL , 5)
        self.lower_lim_tc = simple_label_tc(self, "lower limit", 0.0, "real")
        self.upper_lim_tc = simple_label_tc(self, "upper limit", 0.0, "real")
        self.axis_choice = wx.Choice(self, wx.ID_ANY)
        self.axis_choice.Append("x")
        self.axis_choice.Append("y1")
        self.axis_choice.Append("y2")
        self.axis_choice.Select(0)
        self.set_lim_button = wx.Button(self, wx.ID_ANY, "Set axis limits")
        self.set_lim_button.Bind(wx.EVT_BUTTON, self.OnSetLim)
        self.auto_lim_button = wx.Button(self, wx.ID_ANY, "Auto limits")
        self.auto_lim_button.Bind(wx.EVT_BUTTON, self.OnAutoLim)
        self.ctrl_sizer.Add(self.lower_lim_tc, 0, wx.ALL | \
                wx.ALIGN_CENTER_VERTICAL , 5)
        self.ctrl_sizer.Add(self.upper_lim_tc, 0, wx.ALL | \
                wx.ALIGN_CENTER_VERTICAL , 5)
        self.ctrl_sizer.Add(self.axis_choice, 0, wx.ALL | \
                wx.ALIGN_CENTER_VERTICAL , 5)
        self.ctrl_sizer.Add(self.set_lim_button, 0, wx.ALL | \
                wx.ALIGN_CENTER_VERTICAL , 5)
        self.ctrl_sizer.Add(self.auto_lim_button, 0, wx.ALL | \
                wx.ALIGN_CENTER_VERTICAL , 5)
        self.sizer.Add(self.ctrl_sizer, 0, wx.ALL | wx.LEFT, 5)
        self.sizer.Add(self.canvas, 0, wx.ALL | \
                       wx.LEFT, 5)
コード例 #4
0
 def init_ui(self):
     """Creates the user interface"""
     self.init_menu()
     self.SetSize(wx.Size(640, 480))
     self.main_panel = wx.Panel(self)
     self.main_panel_sizer = wx.BoxSizer(wx.VERTICAL)
     self.figure = Figure()
     self.canvas = FigureCanvas(self.main_panel, wx.ID_ANY, self.figure)
     self.main_panel_sizer.Add(self.canvas, 1, sizer_flags, 0)
     self.toolbar = NavigationToolbar2Wx(self.canvas)
     self.toolbar.Realize()
     if wx.Platform == '__WXMAC__':
         self.SetToolBar(self.toolbar)
     else:
         tw, th = self.toolbar.GetSizeTuple()
         fw, fh = self.canvas.GetSizeTuple()
         self.toolbar.SetSize(wx.Size(fw, th))
         self.main_panel_sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND, 0)
     self.toolbar.update()
     self.main_panel.SetSizerAndFit(self.main_panel_sizer)
コード例 #5
0
 def __init__(self):
     wx.Frame.__init__(self,
                       None,
                       wx.ID_ANY,
                       title='Matplotlib in Wx',
                       size=(600, 400))
     self.figure = Figure(figsize=(6, 4), dpi=100)
     self.axes = self.figure.add_subplot(111)
     x = np.arange(0, 6, .01)
     y = np.sin(x**2) * np.exp(-x)
     self.axes.plot(x, y)
     self.canvas = FigureCanvas(self, wx.ID_ANY, self.figure)
     self.sizer = wx.BoxSizer(wx.VERTICAL)
     self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.EXPAND)
     self.toolbar = NavigationToolbar2Wx(self.canvas)
     self.toolbar.Realize()
     self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
     self.toolbar.Show()
     self.SetSizer(self.sizer)
     self.Fit()
コード例 #6
0
    def __init__(self, *args, **kwds):
        kwds["style"] = wx.TAB_TRAVERSAL
        wx.Panel.__init__(self, *args, **kwds)
        self.label_1 = wx.StaticText(self, -1, "State")
        self.label_2 = wx.StaticText(self, -1, "Frame Nr")
        self.label_3 = wx.StaticText(self, -1, "Node ID")
        self.axes = wx.CheckBox(self, -1, "auto Axes")
        self.axes.SetValue(1)

        self.calibrated = wx.StaticText(self, -1, "not calibrated")
        self.frame_num = wx.StaticText(self, -1, "xxxxxxxx")
        self.node_id = wx.StaticText(self, -1, "xxxxxxxxxxx")

        self.fig = Figure((5, 4), 75)
        self.canvas = FigureCanvasWxAgg(self, -1, self.fig)
        self.toolbar = NavigationToolbar2Wx(self.canvas)

        self.__set_properties()
        self.__do_layout()
        self.__init_plot()
        self.toolbar.Realize()
        EVT_DATA_EVENT(self, self.display_data)
コード例 #7
0
    def __init__(self,
                 parent,
                 orientation=wx.VERTICAL,
                 title='',
                 dpi=None,
                 params=None,
                 **kwargs):

        super(Graph, self).__init__(orientation)
        #initialize some font settings for matplotlib
        if params == None:
            params = {
                'axes.labelsize': 16,
                'font.size': 14,
                'legend.fontsize': 14,
                'xtick.labelsize': 12,
                'ytick.labelsize': 12
            }
        matplotlib.rcParams.update(params)

        self.figure = Figure(dpi=dpi, figsize=(2, 2), **kwargs)
        self.canvas = FigureCanvas(parent, wx.NewId(), self.figure)
        self.sub_plots = _plot_list(self.figure)
        self.sub_plots.append(self.figure.add_subplot(111), title)
        self.toolbar = NavigationToolbar2Wx(self.canvas)

        ###Create some extra controls for the toolbar###
        self.cb_grid = wx.CheckBox(self.toolbar, wx.NewId(), 'Show Grid')
        btn_mark = wx.Button(self.toolbar, wx.NewId(), 'Mark selection')
        #btn_rem = wx.Button(parent, wx.NewId(), 'Remove_graph')
        self.cursor_pos = wx.StaticText(
            self.toolbar,
            wx.NewId(),
            'x=0.0000, y=0.0000            ',
            style=wx.ALIGN_RIGHT | wx.ST_ELLIPSIZE_END | wx.ST_NO_AUTORESIZE)

        ####add extra controls to toolbar####
        self.toolbar.AddControl(self.cb_grid)
        self.toolbar.AddControl(btn_mark)
        self.toolbar.AddStretchableSpace()
        self.toolbar.AddControl(self.cursor_pos)
        #self.toolbar.AddStretchableSpace()

        #needed to update the layout
        self.toolbar.Realize()

        #######Main layout#######
        v_sizer = wx.BoxSizer(wx.VERTICAL)
        v_sizer.Add(self.canvas, 1, wx.EXPAND)
        v_sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
        #Add to self
        self.Add(v_sizer, 1, wx.EXPAND)

        ###Set title and other things###
        self.orientation = orientation
        #layout of plots (height, width, count)
        self.layout = (1, 1, 1)
        self.cb_grid.SetValue(True)
        self.sub_plots.show_grid(True)

        #connect the buttons to event handlers
        self.cb_grid.Connect(-1, -1, wx.wxEVT_COMMAND_CHECKBOX_CLICKED,
                             self._on_cb_grid)
        btn_mark.Connect(-1, -1, wx.wxEVT_COMMAND_BUTTON_CLICKED,
                         self._on_mark)
        #btn_rem.Connect(-1, -1, wx.wxEVT_COMMAND_BUTTON_CLICKED, self.on_rem)

        self.canvas.mpl_connect('motion_notify_event',
                                self._UpdateCursorInformation)
コード例 #8
0
    def show_plot(name, plot_args):
        pwin = wx.Frame(root, -1, name)

        #iplot.figure.clear() #delaxes(plot)
        figure = Figure(facecolor='#ffffff')
        plot = [gen_plot(figure, plot_args)]

        #iplot.figure.clear()
        #iplot.figure.add_axes(plot)

        frame_box = wx.BoxSizer(wx.VERTICAL)
        pwin.SetSizer(frame_box)

        graph_panel = wx.Panel(pwin, -1, style=wx.SUNKEN_BORDER)
        graph_vbox = wx.BoxSizer(wx.VERTICAL)
        graph_panel.SetSizer(graph_vbox)

        canvas = FigureCanvasWx(graph_panel, -1, figure)
        canvas.draw()
        graph_vbox.Add(canvas, 1, wx.ALL | wx.EXPAND)

        toolbar = NavigationToolbar2Wx(canvas)
        toolbar.Realize()
        graph_vbox.Add(toolbar, 0, wx.LEFT | wx.EXPAND)
        toolbar.update()

        edit_panel = wx.Panel(pwin, -1, style=wx.SUNKEN_BORDER)
        edit_box = wx.GridSizer(4, 2)
        edit_panel.SetSizer(edit_box)

        grid_items = []

        def make_entry(name, default=''):
            grid_items.append((wx.StaticText(edit_panel, -1, name), 0, 0))
            id = wx.NewId()
            entry = wx.TextCtrl(edit_panel, id, default)  #, size=(150, -1))
            grid_items.append((entry, 1, wx.RIGHT | wx.EXPAND))
            return entry

        def set_attributes(*args):
            try:
                if hasattr(plot[0], 'iplot_errorbar'):
                    loc = {}
                    try:
                        expression, initial = expr_entry.GetValue().split('@')
                        symbols, points = ifit.read_min_mean_max_file(
                            plot[0].filename)
                        fit=ifit.IFit(expression,points,symbols,\
                               condition=cond_entry.GetValue())
                        variables = ifit.restricted_eval(
                            'dict(%s)' % initial, loc)
                        variables, least_squares, hessian = fit.fit(
                            **variables)
                        fit.scatter_points = 0
                        if scatter_entry.GetValue():
                            fit.scatter_points = int(scatter_entry.GetValue())
                        if fit.scatter_points:
                            fit.iterative_fit(default_output_prefix \
                               + '_scatter.csv', **variables)
                        for key, value in variables.items():
                            log_msg('%s = %g' % (key, value))
                        log_msg('least_squares=%s' % least_squares)
                        log_msg('hessian=%s' % str(hessian))
                        bound_min, bound_max = \
                           plot[0].get_xaxis().get_data_interval().get_bounds()
                        if bound_min == bound_max:
                            return
                        new_ydata = []
                        new_xdata = numpy.arange(bound_min, bound_max, \
                               (bound_max - bound_min) / 200.0, numpy.float)
                        # str() to convert from unicode
                        #extrapolate_variable = str(extrap_entry.GetValue())
                        #if fit.scatter_points:
                        #    extrap = lambda f, c: fit.extrapolate_with_errors(**c)
                        #else:
                        #    extrap = lambda f, c: fit.extrapolate(**c)
                        #for item in new_xdata:
                        #    coordinates = {extrapolate_variable:item}
                        #    #coordinates=ifit.restricted_eval('dict(%s)' % item,loc)
                        #    e = extrap(fit, coordinates)
                        #    new_ydata.append(e)
                        #    print 'extrapolation %s -> %s' % (item,str(e))
                        #### replaced by
                        for item in new_xdata:
                            new_ydata.append(fit.f(**{IPlot.indices[0]: item}))
                        plot[0] = gen_plot(figure, plot_args)
                        if fit.scatter_points:
                            low, mid, high = [], [], []
                            for h, m, l in new_ydata:
                                low.append(l)
                                mid.append(m)
                                high.append(h)
                            plot[0].plot(new_xdata, low, color='#ff5555')
                            plot[0].plot(new_xdata, mid, color='#ff0000')
                            plot[0].plot(new_xdata, high, color='#bb0000')
                        else:
                            plot[0].plot(new_xdata, new_ydata, color='r')
                    except Exception, e:
                        log_msg(e)
                        log_msg('NO FIT')
                plot[0].set_xlabel(xlabel_entry.GetValue())
                plot[0].set_ylabel(ylabel_entry.GetValue())
                plot[0].set_title(title_entry.GetValue())
                plot[0].set_axis_bgcolor(background_entry.GetValue())
                figure.set_facecolor(background_entry.GetValue())
                canvas.draw()
            except Exception, e:
                traceback.print_tb(sys.exc_info()[2])
                dlg = wx.MessageDialog(None, 'Error setting preferences:\t' + \
                        str(e), style=wx.ICON_ERROR | wx.OK)
                dlg.ShowModal()