コード例 #1
0
    def __init__(self, ):
        wx.Frame.__init__(self, None, -1, 'CanvasFrame', size=(550, 350))

        self.SetBackgroundColour(wxc.NamedColour("WHITE"))

        self.figure = Figure()
        self.axes = self.figure.add_subplot(111)
        t = np.arange(0.0, 3.0, 0.01)
        s = np.sin(2 * np.pi * t)

        self.axes.plot(t, s)
        self.axes.set_xlabel('t')
        self.axes.set_ylabel('sin(t)')
        self.figure_canvas = FigureCanvas(self, -1, self.figure)

        # Note that event is a MplEvent
        self.figure_canvas.mpl_connect('motion_notify_event',
                                       self.UpdateStatusBar)
        self.figure_canvas.Bind(wx.EVT_ENTER_WINDOW, self.ChangeCursor)

        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.figure_canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
        self.SetSizer(self.sizer)
        self.Fit()

        self.statusBar = wx.StatusBar(self, -1)
        self.SetStatusBar(self.statusBar)

        self.toolbar = NavigationToolbar2Wx(self.figure_canvas)
        self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
        self.toolbar.Show()
コード例 #2
0
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, -1, title, size=(550, 350))
        self.SetBackgroundColour(wxc.NamedColour("WHITE"))

        self.figure = Figure()
        self.axes = self.figure.add_subplot(111)

        self.canvas = FigureCanvas(self, -1, self.figure)

        self.change_plot(0)

        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.add_buttonbar()
        self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
        self.add_toolbar()  # comment this out for no toolbar

        menuBar = wx.MenuBar()

        # File Menu
        menu = wx.Menu()
        menu.Append(wx.ID_EXIT, "E&xit\tAlt-X", "Exit this simple sample")
        menuBar.Append(menu, "&File")

        if IS_GTK or IS_WIN:
            # Equation Menu
            menu = wx.Menu()
            for i, (mt, func) in enumerate(functions):
                bm = mathtext_to_wxbitmap(mt)
                item = wx.MenuItem(menu, 1000 + i, " ")
                item.SetBitmap(bm)
                menu.AppendItem(item)
                self.Bind(wx.EVT_MENU, self.OnChangePlot, item)
            menuBar.Append(menu, "&Functions")

        self.SetMenuBar(menuBar)

        self.SetSizer(self.sizer)
        self.Fit()
    def __init__(self,
                 parent,
                 sf,
                 shapes2,
                 size,
                 use_grid,
                 permission=False,
                 sites_bouger=[]):
        wx.Panel.__init__(self, parent, size=size)
        self.SetBackgroundColour(wxc.NamedColour("BLACK"))
        self.permission = permission

        self.figure = Figure(dpi=65)  #figsize=(16,9))
        self.figure.set_size_inches(1, 1, forward=True)

        #self.axes.xaxis.set_ticks_position('bottom')
        #self.axes.yaxis.set_ticks_position('left')
        self.axes = self.figure.add_subplot(
            111, frameon=False)  #plt.subplot(111, projection="lambert")

        user_grid = False
        if use_grid:

            d = (0, 0.01, 0.99, 0.99)
            self.axes.grid(use_grid)

        else:
            #self.axes = self.figure.add_subplot(111, frameon=False)
            d = (0, 0, 0.999, 0.999)
            self.axes.get_xaxis().set_visible(False)
            self.axes.get_yaxis().set_visible(False)

        self.w, self.h = self.figure.get_size_inches() * self.figure.dpi
        CanvasPanel3.w = size[0]
        self.axes.set_position(
            d
        )  # x-top-left-corner, y-top-left-corner, x-width, y-width (in pixels)

        self.canvas = FigureCanvas(self, -1, self.figure)

        if permission:
            self.axes.clear()
            self.canvas.Update()
            recs = sf.records()

            shapes = sf.shapes
            Nshp = len(shapes)
            """
			for nshp in xrange(Nshp):
				ptchs = []
				pts = array(shapes[nshp].points)
				if shapes[nshp].shapeType == 5:
					prt = shapes[nshp].parts
					par = list(prt) + [pts.shape[0]]
					for pij in xrange(len(prt)):
						ptchs.append(Polygon(pts[par[pij]:par[pij+1]]))
			
				self.axes.add_collection(PatchCollection(ptchs,facecolor='none',edgecolor='b', linewidths=2))
			"""
            """
			data = [(50, 50), (70, 70)]
			pp = []
			for x, y in data :
				c = Circle((x,y), 0.5)
				pp.append(c)
			
			p = PatchCollection(pp, cmap=mpl.cm.jet, alpha=0.4)
			self.axes.add_collection(PatchCollection(p,facecolor='none',edgecolor='r', linewidths=2))
			"""
            #self.axes.scatter(50, 50, s=10, c='g', marker='^', label='Two Fires')
            #print "Len shapes :", len(shapes)
            """
			for obj in range(0, len(shapes)):
						for pt in range(0, len(shapes[obj].points)):
							if shapes[obj].points[pt] != shapes2[obj].points[pt]:
								print "------------------------------------"
								print "Not equal !"
								print "Original :",shapes[obj].points[pt], obj, pt
								print "Modifie :",shapes2[obj].points[pt], obj, pt
			"""

            #t = [ [147.83058185027457, -42.27884684129017] ,[146.66141197230283, -41.096120875508596] ]

            self.axes.triplot(Triangulation.points[:, 0],
                              Triangulation.points[:, 1], Triangulation.triang)
            self.axes.plot(Triangulation.points[:, 0],
                           Triangulation.points[:, 1], 'r.')

            shapes = shapes2
            Nshp = len(shapes)
            import random
            color = random.choice(["g", "r", "y"])
            for nshp in xrange(Nshp):
                ptchs = []
                pts = array(shapes[nshp].points)
                if shapes[nshp].shapeType == 5:
                    prt = shapes[nshp].parts
                    par = list(prt) + [pts.shape[0]]
                    for pij in xrange(len(prt)):
                        ptchs.append(Polygon(pts[par[pij]:par[pij + 1]]))
                self.axes.add_collection(
                    PatchCollection(ptchs,
                                    facecolor='none',
                                    edgecolor="black",
                                    linewidths=1.5))
            """
			pp = [
			      [146.661411968, -41.09612087949996] , [146.66141197230283, -41.096120875508596]

					#(142.89579288266205, -43.922664989702909), 
					#(142.89579288266205, -43.922664989702909)
				]
			"""
            #ptchs.append(Circle(pp[0], 0.001))

            #self.axes.add_collection(PatchCollection(ptchs,facecolor='r',edgecolor="r", linewidths= 5))
            #ptchs.append(Circle(pp[1], 0.001))
            #self.axes.add_collection(PatchCollection(ptchs,facecolor='g',edgecolor="g", linewidths= 0.1, alpha=0.9))
            original = {
                'family': 'Courier New',
                'color': 'green',
                'weight': 'bold',
                'size': 12,
            }
            modified = {
                'family': 'Courier New',
                'color': 'red',
                'weight': 'bold',
                'size': 12,
            }

            usb = self.GetTopLevelParent(
            ).rightpanel.get_original_per_sites_bouger()

            for pp in sites_bouger:
                self.axes.plot(pp[0][0][0], pp[0][0][1], 'r+')  # modifie
                self.axes.plot(pp[1][0][0], pp[1][0][1], 'g+')  # original
                #self.axes.text(pp[0][0][0], pp[0][0][1], "Modifie" , fontdict = modified, ha='left')
                #self.axes.text(pp[1][0][0], pp[1][0][1], "Original" , fontdict = original, ha='left')
                for tt in usb:
                    if tt == complex(pp[0][0][0], pp[0][0][1]):
                        v = usb[tt]
                        self.axes.text(pp[0][0][0],
                                       pp[0][0][1],
                                       u"Modifié ( " + str(v[2]) + " )",
                                       fontdict=modified,
                                       ha='left')
                        self.axes.text(pp[1][0][0],
                                       pp[1][0][1],
                                       "Original ( " + str(v[3]) + " )",
                                       fontdict=original,
                                       ha='left')

        self.figure.canvas.mpl_connect('motion_notify_event',
                                       self.StatusBarUpdate)

        self.canvas.draw()
        CanvasPanel.draw_map = True

        self.axes.axis(
            'scaled'
        )  # si cet instruction n'est pas activé , il n'y aura pas d'affichage

        self.sizer = wx.BoxSizer(wx.VERTICAL)

        self.toolbar = CustomNavToolbar(self.canvas)
        self.toolbar.DeleteToolByPos(6)

        self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
        self.SetSizer(self.sizer)
        self.Fit()
    def __init__(self, parent, sf, size, use_grid):
        wx.Panel.__init__(self, parent, size=size)
        self.SetBackgroundColour(wxc.NamedColour("BLACK"))
        self.selection_coords = []
        self.draw_selection = False

        self.figure = Figure(figsize=(10, 12), dpi=65)  #figsize=(16,9))
        self.figure.set_size_inches(1, 1, forward=True)

        #self.axes.xaxis.set_ticks_position('bottom')
        #self.axes.yaxis.set_ticks_position('left')
        self.axes = self.figure.add_subplot(111, frameon=False)
        #self.axes.clear()
        #self.Refresh()

        user_grid = False

        d = (0, 0, 0.999, 0.999)

        self.axes.get_xaxis().set_visible(False)
        self.axes.get_yaxis().set_visible(False)

        self.w, self.h = self.figure.get_size_inches() * self.figure.dpi
        CanvasPanel.w = size[0]
        self.axes.set_position(
            d
        )  # x-top-left-corner, y-top-left-corner, x-width, y-width (in pixels)
        self.canvas = FigureCanvas(self, -1, self.figure)

        recs = sf.records()
        shapes = sf.shapes
        Nshp = len(shapes)
        for nshp in xrange(Nshp):
            ptchs = []
            pts = array(shapes[nshp].points)
            if shapes[nshp].shapeType == 5:
                prt = shapes[nshp].parts
                par = list(prt) + [pts.shape[0]]
                for pij in xrange(len(prt)):
                    ptchs.append(Polygon(pts[par[pij]:par[pij + 1]]))
            else:
                #print "type shape >> ",shapes[nshp].shapeType
                pass
            self.axes.add_collection(
                PatchCollection(ptchs,
                                facecolor='none',
                                edgecolor='black',
                                linewidths=1.5))
        #self.axes.plot(146.661411968, -41.09612087949996, 'g+')
        #self.axes.plot(146.66141197230283, -41.096120875508596, 'r+')
        """
        circle = Circle((100, 100), 3)
        ptchs.append(circle)
        p = PatchCollection(ptchs)
        self.axes.add_collection(p)
		"""
        self.figure.canvas.mpl_connect('key_press_event', toggle_selector)
        self.figure.canvas.mpl_connect('motion_notify_event',
                                       self.StatusBarUpdate)

        #self.canvas.Refresh()
        CanvasPanel.draw_map = True

        self.axes.axis(
            'scaled'
        )  # si cet instruction n'est pas activé , il n'y aura pas d'affichage
        self.canvas.draw()

        #print self.figure.canvas.manager
        toggle_selector.RS = RectangleSelector(
            self.axes,
            self.line_select_callback,
            drawtype='box',
            useblit=False,
            button=[1],  # don't use middle button , button=[1, 3]
            minspanx=5,
            minspany=5,
            spancoords='pixels',
            interactive=True)

        toggle_selector.RS.set_active(False)
        self.sizer = wx.BoxSizer(wx.VERTICAL)

        self.toolbar = CustomNavToolbar(self.canvas)
        self.toolbar.DeleteToolByPos(6)

        self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
        self.SetSizer(self.sizer)
        self.Fit()
    def __init__(self, parent, size, permission=False):
        wx.Panel.__init__(self, parent, size=size)
        self.SetBackgroundColour(wxc.NamedColour("BLACK"))
        self.permission = permission

        self.figure = Figure(dpi=65)  #figsize=(16,9))
        self.figure.set_size_inches(1, 1, forward=True)

        #self.axes.xaxis.set_ticks_position('bottom')
        #self.axes.yaxis.set_ticks_position('left')

        self.axes = self.figure.add_subplot(
            111, frameon=False)  #plt.subplot(111, projection="lambert")

        d = (0, 0, 0.999, 0.999)
        self.axes.get_xaxis().set_visible(False)
        self.axes.get_yaxis().set_visible(False)

        self.w, self.h = self.figure.get_size_inches() * self.figure.dpi
        CanvasPanel2.w = size[0]
        self.axes.set_position(
            d
        )  # x-top-left-corner, y-top-left-corner, x-width, y-width (in pixels)

        self.canvas = FigureCanvas(self, -1, self.figure)

        if permission:
            self.axes.triplot(Triangulation.points[:, 0],
                              Triangulation.points[:, 1], Triangulation.triang)
            self.axes.plot(Triangulation.points[:, 0],
                           Triangulation.points[:, 1], 'r.')
            #Triangulation.points = []
            #Triangulation.triang = []

        self.figure.canvas.mpl_connect('motion_notify_event',
                                       self.StatusBarUpdate)

        self.canvas.draw()

        self.axes.axis(
            'scaled'
        )  # si cet instruction n'est pas activé , il n'y aura pas d'affichage

        self.sizer = wx.BoxSizer(wx.VERTICAL)

        self.toolbar = CustomNavToolbar(self.canvas)
        self.toolbar.DeleteToolByPos(6)

        #self.toolbar.AddLabelTool(12,'',wx.Bitmap('save_as2.png'))#wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_TOOLBAR, (16,16)))

        #self.toolbar.Realize()
        #self.toolbar.wx_ids['Selection'] = 500

        #self.sizer.Add(self.toolbar, 0,wx.LEFT | wx.TOP | wx.GROW)
        #self.toolbar.update()
        #print self.toolbar.wx_ids['Selection']

        #self.toolbar.ToggleTool(self.toolbar.wx_ids['Pan'], False)

        self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
        self.SetSizer(self.sizer)
        self.Fit()