示例#1
0
 def show_contour_minmaxstep(self):
     showlay = self.get_layers()
     lay = []
     for i in range( len(showlay) ):
         if showlay[i]: lay.append( i )
     min,max,step = self.get_minmaxstep()
     print arange(min,max,step)
     showContours( lay, arange(min,max,step) )
示例#2
0
    def __do_layout(self):
        # begin wxGlade: pwxChartParms.__do_layout
        sizer_1 = wx.BoxSizer(wx.VERTICAL)
        sizer_2 = wx.BoxSizer(wx.VERTICAL)
        sizer_6 = wx.StaticBoxSizer(self.sizer_6_staticbox, wx.HORIZONTAL)
        sizer_5 = wx.StaticBoxSizer(self.sizer_5_staticbox, wx.HORIZONTAL)
        sizer_4 = wx.StaticBoxSizer(self.sizer_4_staticbox, wx.HORIZONTAL)
        sizer_3 = wx.StaticBoxSizer(self.sizer_3_staticbox, wx.HORIZONTAL)
        sizer_3.Add(self.label_1, 0,
                    wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.ADJUST_MINSIZE, 1)
        sizer_3.Add(self.label_ctrl_trace, 1,
                    wx.ALIGN_CENTER_VERTICAL | wx.ADJUST_MINSIZE, 0)
        sizer_2.Add(sizer_3, 0, wx.EXPAND, 0)
        sizer_4.Add(self.button_trace_color, 1, wx.EXPAND | wx.ADJUST_MINSIZE,
                    0)
        #sizer_4.Add(self.spin_ctrl_1, 1, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
        sizer_4.Add(
            self.slider_ctrl_linewd, 1,
            wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ADJUST_MINSIZE, 0)
        sizer_4.Add(self.combo_box_line_type, 0,
                    wx.ALIGN_CENTER_VERTICAL | wx.ADJUST_MINSIZE, 0)
        sizer_2.Add(sizer_4, 0, wx.EXPAND, 0)
        sizer_5.Add(self.button_marker_color, 1, wx.EXPAND | wx.ADJUST_MINSIZE,
                    0)
        #sizer_5.Add(self.spin_ctrl_marker, 1, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
        sizer_5.Add(
            self.slider_ctrl_marker, 1,
            wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ADJUST_MINSIZE, 0)
        sizer_5.Add(self.combo_box_marker_type, 0,
                    wx.ALIGN_CENTER_VERTICAL | wx.ADJUST_MINSIZE, 0)
        sizer_2.Add(sizer_5, 0, wx.EXPAND, 0)
        #sizer_2.Add(self.text_ctrl_1, 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        #self.sizer = wx.BoxSizer(wx.VERTICAL)
        sizer_2.Add(self.m_canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
        sizer_6.Add(self.button_3, 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0)
        sizer_6.Add(self.button_4, 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0)
        sizer_6.Add(self.button_5, 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0)
        sizer_2.Add(sizer_6, 0, wx.EXPAND, 0)
        sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
        self.SetAutoLayout(True)
        self.SetSizer(sizer_1)
        sizer_1.Fit(self)
        sizer_1.SetSizeHints(self)
        self.Layout()
        # end wxGlade

        self.m_firstAxes = None
        self.x = arange(10) * 1.0
        self.y = arange(10) * 1.0
        self.label = ''
        self.lineColor = 'b'
        self.lineStyle = '-'
        self.lineWidth = 1
        self.markerType = ''
        self.markerColor = 'r'
        self.markerSize = 0
        self.master = None
        self.linenumber = 0
示例#3
0
文件: barchart.py 项目: AMDmi3/gem5
    def gen_colors(self, count):
        cmap = matplotlib.cm.get_cmap(self.colormap)
        if count == 1:
            return cmap([0.5])

        if count < 5:
            return cmap(arange(5) / float(4))[:count]

        return cmap(arange(count) / float(count - 1))
示例#4
0
    def gen_colors(self, count):
        cmap = matplotlib.cm.get_cmap(self.colormap)
        if count == 1:
            return cmap([0.5])

        if count < 5:
            return cmap(arange(5) / float(4))[:count]

        return cmap(arange(count) / float(count - 1))
示例#5
0
 def init_plot_data(self):
     # jdh you can add a subplot directly from the fig rather than
     # the fig manager
     a = self.fig.add_subplot(111)
     self.x = numerix.arange(120.0)*2*numerix.pi/120.0
     self.x.resize((100,120))
     self.y = numerix.arange(100.0)*2*numerix.pi/100.0
     self.y.resize((120,100))
     self.y = numerix.transpose(self.y)
     z = numerix.sin(self.x) + numerix.cos(self.y)
     self.im = a.imshow( z, cmap=cm.jet)#, interpolation='nearest')
示例#6
0
 def init_plot_data(self):
     # jdh you can add a subplot directly from the fig rather than
     # the fig manager
     a = self.fig.add_subplot(111)
     self.x = numerix.arange(120.0) * 2 * numerix.pi / 120.0
     self.x.resize((100, 120))
     self.y = numerix.arange(100.0) * 2 * numerix.pi / 100.0
     self.y.resize((120, 100))
     self.y = numerix.transpose(self.y)
     z = numerix.sin(self.x) + numerix.cos(self.y)
     self.im = a.imshow(z, cmap=cm.jet)  #, interpolation='nearest')
示例#7
0
 def init_plot_data(self):
     # jdh you can add a subplot directly from the fig rather than
     # the fig manager
     a = self.fig.add_axes([0.075, 0.1, 0.75, 0.85])
     cax = self.fig.add_axes([0.85, 0.1, 0.075, 0.85])
     self.x = numerix.arange(120.0) * 2 * numerix.pi / 120.0
     self.x.resize((100, 120))
     self.y = numerix.arange(100.0) * 2 * numerix.pi / 100.0
     self.y.resize((120, 100))
     self.y = numerix.transpose(self.y)
     z = numerix.sin(self.x) + numerix.cos(self.y)
     self.im = a.imshow(z, cmap=cm.jet)  #, interpolation='nearest')
     self.fig.colorbar(self.im, cax=cax, orientation='vertical')
示例#8
0
 def init_plot_data(self):
     # jdh you can add a subplot directly from the fig rather than
     # the fig manager
     a = self.fig.add_axes([0.075,0.1,0.75,0.85])
     cax = self.fig.add_axes([0.85,0.1,0.075,0.85])
     self.x = numerix.arange(120.0)*2*numerix.pi/120.0
     self.x.resize((100,120))
     self.y = numerix.arange(100.0)*2*numerix.pi/100.0
     self.y.resize((120,100))
     self.y = numerix.transpose(self.y)
     z = numerix.sin(self.x) + numerix.cos(self.y)
     self.im = a.imshow( z, cmap=cm.jet)#, interpolation='nearest')
     self.fig.colorbar(self.im,cax=cax,orientation='vertical')
示例#9
0
    def writeHatches(self):
        hatchDict = dict()
        sidelen = 144.0
        density = 24.0
        for lst, name in self.hatchPatterns.items():
            ob = self.reserveObject('hatch pattern')
            hatchDict[name] = ob
            res = {
                'Procsets':
                [Name(x) for x in "PDF Text ImageB ImageC ImageI".split()]
            }
            self.beginStream(
                ob.id, None, {
                    'Type': Name('Pattern'),
                    'PatternType': 1,
                    'PaintType': 1,
                    'TilingType': 1,
                    'BBox': [0, 0, sidelen, sidelen],
                    'XStep': sidelen,
                    'YStep': sidelen,
                    'Resources': res
                })

            # lst is a tuple of stroke color, fill color,
            # number of - lines, number of / lines,
            # number of | lines, number of \ lines
            rgb = lst[0]
            self.output(rgb[0], rgb[1], rgb[2], Op.setrgb_stroke)
            if lst[1] is not None:
                rgb = lst[1]
                self.output(rgb[0], rgb[1], rgb[2], Op.setrgb_nonstroke, 0, 0,
                            sidelen, sidelen, Op.rectangle, Op.fill)
            if lst[2]:  # -
                for j in arange(0.0, sidelen, density / lst[2]):
                    self.output(0, j, Op.moveto, sidelen, j, Op.lineto)
            if lst[3]:  # /
                for j in arange(0.0, sidelen, density / lst[3]):
                    self.output(0, j, Op.moveto, sidelen - j, sidelen,
                                Op.lineto, sidelen - j, 0, Op.moveto, sidelen,
                                j, Op.lineto)
            if lst[4]:  # |
                for j in arange(0.0, sidelen, density / lst[4]):
                    self.output(j, 0, Op.moveto, j, sidelen, Op.lineto)
            if lst[5]:  # \
                for j in arange(sidelen, 0.0, -density / lst[5]):
                    self.output(sidelen, j, Op.moveto, j, sidelen, Op.lineto,
                                j, 0, Op.moveto, 0, j, Op.lineto)
            self.output(Op.stroke)

            self.endStream()
        self.writeObject(self.hatchObject, hatchDict)
示例#10
0
    def writeHatches(self):
	hatchDict = dict()
	sidelen = 144.0
	density = 24.0
	for lst, name in self.hatchPatterns.items():
	    ob = self.reserveObject('hatch pattern')
	    hatchDict[name] = ob
	    res = { 'Procsets': 
		    [ Name(x) for x in "PDF Text ImageB ImageC ImageI".split() ] }
	    self.beginStream(
		ob.id, None, 
		{ 'Type': Name('Pattern'),
		  'PatternType': 1, 'PaintType': 1, 'TilingType': 1,
		  'BBox': [0, 0, sidelen, sidelen],
		  'XStep': sidelen, 'YStep': sidelen,
		  'Resources': res })

	    # lst is a tuple of stroke color, fill color, 
	    # number of - lines, number of / lines, 
	    # number of | lines, number of \ lines
	    rgb = lst[0]
	    self.output(rgb[0], rgb[1], rgb[2], Op.setrgb_stroke)
	    if lst[1] is not None:
		rgb = lst[1]
		self.output(rgb[0], rgb[1], rgb[2], Op.setrgb_nonstroke,
			    0, 0, sidelen, sidelen, Op.rectangle,
			    Op.fill)
	    if lst[2]:		# -
		for j in arange(0.0, sidelen, density/lst[2]):
		    self.output(0, j, Op.moveto,
				sidelen, j, Op.lineto)
	    if lst[3]:		# /
		for j in arange(0.0, sidelen, density/lst[3]):
		    self.output(0, j, Op.moveto,
				sidelen-j, sidelen, Op.lineto,
				sidelen-j, 0, Op.moveto,
				sidelen, j, Op.lineto)
	    if lst[4]:		# |
		for j in arange(0.0, sidelen, density/lst[4]):
		    self.output(j, 0, Op.moveto,
				j, sidelen, Op.lineto)
	    if lst[5]:		# \
		for j in arange(sidelen, 0.0, -density/lst[5]):
		    self.output(sidelen, j, Op.moveto,
				j, sidelen, Op.lineto,
				j, 0, Op.moveto,
				0, j, Op.lineto)
	    self.output(Op.stroke)

	    self.endStream()
	self.writeObject(self.hatchObject, hatchDict)
示例#11
0
    def createDBGraph(self, widget):
        self.axis.clear()
        self.axis.set_xlabel('Samples (n)')
        self.axis.set_ylabel('Value (-)')
        self.axis.set_title('Another Graph (click on the columnheader to sort)')
        self.axis.grid(True)
 
        # get columns from listmodel
        age = []
        for row in self.listmodel:
            age.append(row[1])
        size = []
        for row in self.listmodel:
            size.append(row[2])
             
        # get number of rows
        N = len(age)
         
        ind = arange(N)  # the x locations for the groups
        width = 0.35       # the width of the bars
        p1 = self.axis.bar(ind, age, width, color='b')
        p2 = self.axis.bar(ind+width, size, width, color='r')
        # destroy graph if it already exists
        while True:
            try:
                self.canvas2.destroy()
                break
            except:
                print "nothing to destroy"
                break
             
        self.canvas2 = FigureCanvasGTK(self.figure) # a gtk.DrawingArea
        self.canvas2.show()
        self.grahview = self.wTree.get_widget("vbox2")
        self.grahview.pack_start(self.canvas2, True, True)
示例#12
0
    def OnInit(self):
        self.timer = wx.PyTimer(self.OnTimer)
        self.numPoints = 0

        self.frame = wxmpl.PlotFrame(None, -1, 'WxMpl Stripchart Demo')
        self.frame.Show(True)

        # The data to plot
        x =  arange(0.0, 200, 0.1)
        y1 = 4*cos(2*pi*(x-1)/5.7)/(6+x) + 2*sin(2*pi*(x-1)/2.2)/(10)
        y2 = y1 + .5
        y3 = y2 + .5
        y4 = y3 + .5

        # Fetch and setup the axes
        axes = self.frame.get_figure().gca()
        axes.set_title('Stripchart Test')
        axes.set_xlabel('t')
        axes.set_ylabel('f(t)')

        # Attach the StripCharter and define its channels
        self.charter = wxmpl.StripCharter(axes)
        self.charter.setChannels([
            TestChannel('ch1', x, y1),
            TestChannel('ch2', x, y2),
            TestChannel('ch3', x, y3),
            TestChannel('ch4', x, y4)
        ])

        # Prime the pump and start the timer
        self.charter.update()
        self.timer.Start(100)
        return True
示例#13
0
 def _process_values(self, b=None):
     """
     Set the _boundaries and _values attributes based on
     the input boundaries and values.  Input boundaries can
     be self.boundaries or the argument b.
     """
     if b is None:
         b = self.boundaries
     if b is not None:
         self._boundaries = nx.array(b)
         if self.values is None:
             self._values = 0.5 * (self._boundaries[:-1] + self._boundaries[1:])
             if isinstance(self.norm, colors.no_norm):
                 self._values = (self._values + 0.00001).astype(nx.Int16)
             return
         self._values = nx.array(self.values)
         return
     if self.values is not None:
         self._values = nx.array(self.values)
         if self.boundaries is None:
             b = nx.zeros(len(self.values) + 1, "d")
             b[1:-1] = 0.5 * (self._values[:-1] - self._values[1:])
             b[0] = 2.0 * b[1] - b[2]
             b[-1] = 2.0 * b[-2] - b[-3]
             self._boundaries = b
             return
         self._boundaries = nx.array(self.boundaries)
         return
     if isinstance(self.norm, colors.no_norm):
         b = nx.arange(self.norm.vmin, self.norm.vmax + 2) - 0.5
     else:
         dv = self.norm.vmax - self.norm.vmin
         b = self.norm.vmin + dv * self._uniform_y(self.cmap.N + 1)
     self._process_values(b)
示例#14
0
    def __init__(self):
        wxFrame.__init__(self,None,-1,
                         'CanvasFrame',size=(550,350))

        self.SetBackgroundColour(wxNamedColor("WHITE"))

        self.figure = Figure()
        self.axes = self.figure.add_subplot(111)
        t = arange(0.0,3.0,0.01)
        s = sin(2*pi*t)
        
        self.axes.plot(t,s)
        self.axes.set_xlabel('Time (s)')
        self.axes.set_ylabel('Price ($)')                
        self.canvas = FigureCanvas(self, -1, self.figure)
        self.canvas.mpl_connect('motion_notify_event', self.mouse_move)
        self.sizer = wxBoxSizer(wxVERTICAL)
        self.sizer.Add(self.canvas, 1, wxLEFT | wxTOP | wxGROW)
        self.SetSizer(self.sizer)
        self.Fit()

        self.statusBar =         wxStatusBar(self, -1)
        self.statusBar.SetFieldsCount(1)
        self.SetStatusBar(self.statusBar)

        self.add_toolbar()  # comment this out for no toolbar

        EVT_PAINT(self, self.OnPaint)
示例#15
0
 def _process_values(self, b=None):
     '''
     Set the _boundaries and _values attributes based on
     the input boundaries and values.  Input boundaries can
     be self.boundaries or the argument b.
     '''
     if b is None:
         b = self.boundaries
     if b is not None:
         self._boundaries = nx.array(b)
         if self.values is None:
             self._values = 0.5 * (self._boundaries[:-1] +
                                   self._boundaries[1:])
             if isinstance(self.norm, colors.no_norm):
                 self._values = (self._values + 0.00001).astype(nx.Int16)
             return
         self._values = nx.array(self.values)
         return
     if self.values is not None:
         self._values = nx.array(self.values)
         if self.boundaries is None:
             b = nx.zeros(len(self.values) + 1, 'd')
             b[1:-1] = 0.5 * (self._values[:-1] - self._values[1:])
             b[0] = 2.0 * b[1] - b[2]
             b[-1] = 2.0 * b[-2] - b[-3]
             self._boundaries = b
             return
         self._boundaries = nx.array(self.boundaries)
         return
     if isinstance(self.norm, colors.no_norm):
         b = nx.arange(self.norm.vmin, self.norm.vmax + 2) - 0.5
     else:
         dv = self.norm.vmax - self.norm.vmin
         b = self.norm.vmin + dv * self._uniform_y(self.cmap.N + 1)
     self._process_values(b)
示例#16
0
    def __init__(self):
        wxFrame.__init__(self,None,-1,
                         'CanvasFrame',size=(550,350))

        self.SetBackgroundColour(wxNamedColor("WHITE"))

        self.figure = Figure()
        self.axes = self.figure.add_subplot(111)
        t = arange(0.0,3.0,0.01)
        s = sin(2*pi*t)
        
        self.axes.plot(t,s)
        self.axes.set_xlabel('Time (s)')
        self.axes.set_ylabel('Price ($)')                
        self.canvas = FigureCanvas(self, -1, self.figure)
        self.canvas.mpl_connect('motion_notify_event', self.mouse_move)
        self.sizer = wxBoxSizer(wxVERTICAL)
        self.sizer.Add(self.canvas, 1, wxLEFT | wxTOP | wxGROW)
        self.SetSizer(self.sizer)
        self.Fit()

        self.statusBar =         wxStatusBar(self, -1)
        self.statusBar.SetFieldsCount(1)
        self.SetStatusBar(self.statusBar)

        self.add_toolbar()  # comment this out for no toolbar
示例#17
0
    def __init__(self):
        self.widgets = gtk.glade.XML('mpl_with_glade.glade')
        self.widgets.signal_autoconnect(GladeHandlers.__dict__)

        self.figure = Figure(figsize=(8,6), dpi=72)
        self.axis = self.figure.add_subplot(111)
        
        t = arange(0.0,3.0,0.01)
        s = sin(2*pi*t)
        self.axis.plot(t,s)
        self.axis.set_xlabel('time (s)')
        self.axis.set_ylabel('voltage')

        self.canvas = FigureCanvasGTK(self.figure) # a gtk.DrawingArea
        self.canvas.show()
        self['vboxMain'].pack_start(self.canvas, gtk.TRUE, gtk.TRUE)
        self['vboxMain'].show()
        
        # below is optional if you want the navigation toolbar
        self.navToolbar = NavigationToolbar(self.canvas, self['windowMain'])
        self.navToolbar.lastDir = '/var/tmp/'
        self['vboxMain'].pack_start(self.navToolbar)
        self.navToolbar.show()

        sep = gtk.HSeparator()
        sep.show()
        self['vboxMain'].pack_start(sep, gtk.TRUE, gtk.TRUE)


        self['vboxMain'].reorder_child(self['buttonClickMe'],-1)
示例#18
0
    def __init__(self, ):
        wx.Frame.__init__(self, None, -1, 'CanvasFrame', size=(550, 350))

        self.SetBackgroundColour(wx.NamedColor("WHITE"))

        self.figure = Figure()
        self.axes = self.figure.add_subplot(111)
        t = arange(0.0, 3.0, 0.01)
        s = sin(2 * 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.statusBar.SetFieldsCount(1)
        self.SetStatusBar(self.statusBar)

        self.toolbar = NavigationToolbar2Wx(self.figure_canvas)
        self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
        self.toolbar.Show()
示例#19
0
    def __init__(self):
        self.widgets = gtk.glade.XML('mpl_with_glade.glade')
        self.widgets.signal_autoconnect(GladeHandlers.__dict__)

        self.figure = Figure(figsize=(8, 6), dpi=72)
        self.axis = self.figure.add_subplot(111)

        t = arange(0.0, 3.0, 0.01)
        s = sin(2 * pi * t)
        self.axis.plot(t, s)
        self.axis.set_xlabel('time (s)')
        self.axis.set_ylabel('voltage')

        self.canvas = FigureCanvasGTK(self.figure)  # a gtk.DrawingArea
        self.canvas.show()
        self['vboxMain'].pack_start(self.canvas, gtk.TRUE, gtk.TRUE)
        self['vboxMain'].show()

        # below is optional if you want the navigation toolbar
        self.navToolbar = NavigationToolbar(self.canvas, self['windowMain'])
        self.navToolbar.lastDir = '/var/tmp/'
        self['vboxMain'].pack_start(self.navToolbar)
        self.navToolbar.show()

        sep = gtk.HSeparator()
        sep.show()
        self['vboxMain'].pack_start(sep, gtk.TRUE, gtk.TRUE)

        self['vboxMain'].reorder_child(self['buttonClickMe'], -1)
示例#20
0
    def init_plot_data(self):
        a = self.fig.add_subplot(111)
        
        x = numerix.arange(120.0)*2*numerix.pi/60.0
        y = numerix.arange(100.0)*2*numerix.pi/50.0
        self.x, self.y = meshgrid(x, y)
        z = numerix.sin(self.x) + numerix.cos(self.y)
        self.im = a.imshow( z, cmap=cm.jet)#, interpolation='nearest')
        
        zmax = numerix.max(numerix.max(z))-ERR_TOL
        ymax_i, xmax_i = numerix.nonzero(
            numerix.greater_equal(z, zmax))
        if self.im.origin == 'upper':
            ymax_i = z.shape[0]-ymax_i
        self.lines = a.plot(xmax_i,ymax_i,'ko')

        self.toolbar.update() # Not sure why this is needed - ADS
示例#21
0
 def __init__(self, infile, varName, rowNum):
     self.rowNum = rowNum
     self.name = varName
     self.y = infile.ReadVar(varName)
     self.x = arange(0,self.y.shape[0])
     print 'y.shape = ' + repr(self.y.shape)
     if len(self.y.shape) == 1:
         (self.mean, self.var, self.error, self.kappa) = stats.Stats(self.y)
示例#22
0
 def init_plot(self):
     # create the initial line
     x = nx.arange(0, 2 * nx.pi, 0.01)
     self.l_pos_a = [((0, 0), (1, 1)), ((0, 1), (1, 0))]
     self.l_pos_b = [((0, 0), (0, 1)), ((1, 1), (1, 0))]
     self.line_c = LineCollection(self.l_pos_a, animated=True)
     line, = p.plot(x, nx.sin(x), animated=False)
     self.ax.add_collection(self.line_c)
示例#23
0
    def points(self,npoints):
        """
        compute arrays of npoints equally spaced
        intermediate points along the great circle.

        input parameter npoints is the number of points
        to compute.

        Returns lons, lats (lists with longitudes and latitudes
        of intermediate points in degrees).

        For example npoints=10 will return arrays lons,lats of 10
        equally spaced points along the great circle.
        """
        # must ask for at least 2 points.
        if npoints <= 1:
            raise ValueError,'npoints must be greater than 1'
        elif npoints == 2:
            return [math.degrees(self.lon1),math.degrees(self.lon2)],[math.degrees(self.lat1),math.degrees(self.lat2)]
        # can't do it if endpoints are antipodal, since
        # route is undefined.
        if self.antipodal:
            raise ValueError,'cannot compute intermediate points on a great circle whose endpoints are antipodal'
        d = self.gcarclen
        delta = 1.0/(npoints-1)
        f = delta*NX.arange(npoints) # f=0 is point 1, f=1 is point 2.
        incdist = self.distance/(npoints-1)
        lat1 = self.lat1
        lat2 = self.lat2
        lon1 = self.lon1
        lon2 = self.lon2
        # perfect sphere, use great circle formula
        if self.f == 0.:
            A = NX.sin((1-f)*d)/math.sin(d)
            B = NX.sin(f*d)/math.sin(d)
            x = A*math.cos(lat1)*math.cos(lon1)+B*math.cos(lat2)*math.cos(lon2)
            y = A*math.cos(lat1)*math.sin(lon1)+B*math.cos(lat2)*math.sin(lon2)
            z = A*math.sin(lat1)               +B*math.sin(lat2)
            lats=NX.arctan2(z,NX.sqrt(x**2+y**2))
            lons=NX.arctan2(y,x)
            lons = map(math.degrees,lons.tolist())
            lats = map(math.degrees,lats.tolist())
        # use ellipsoid formulas
        else:
            latpt = self.lat1
            lonpt = self.lon1
            azimuth = self.azimuth12
            lons = [math.degrees(lonpt)]
            lats = [math.degrees(latpt)]
            for n in range(npoints-2):
                latptnew,lonptnew,alpha21=vinc_pt(self.f,self.a,latpt,lonpt,azimuth,incdist) 
                d,azimuth,a21=vinc_dist(self.f,self.a,latptnew,lonptnew,lat2,lon2) 
                lats.append(math.degrees(latptnew))
                lons.append(math.degrees(lonptnew))
                latpt = latptnew; lonpt = lonptnew
            lons.append(math.degrees(self.lon2))
            lats.append(math.degrees(self.lat2))
        return lons,lats
示例#24
0
 def init_plot_data(self):
     a = self.figmgr.add_subplot(111)
     self.ind = numpy.arange(60)
     tmp = []
     for i in range(60):
         tmp.append(numpy.sin((self.ind + i) * numpy.pi / 15))
     self.X = numpy.array(tmp)
     self.lines = a.plot(self.X[:, 0], 'o')
     self.count = 0
示例#25
0
 def init_plot_data(self):
     a = self.figmgr.add_subplot(111)
     self.ind = numpy.arange(60)
     tmp = []
     for i in range(60):
         tmp.append(numpy.sin((self.ind+i)*numpy.pi/15))
     self.X = numpy.array(tmp)
     self.lines = a.plot(self.X[:,0],'o')
     self.count = 0
示例#26
0
    def __init__(self):
        self.widgets = gtk.glade.XML('mpl_with_glade.glade')
        self.widgets.signal_autoconnect(GladeHandlers.__dict__)

        self['windowMain'].connect('destroy', lambda x: gtk.main_quit())
        self['windowMain'].move(10,10)
        self.figure = Figure(figsize=(8,6), dpi=72)
        self.axis = self.figure.add_subplot(111)
        
        t = arange(0.0,3.0,0.01)
        s = sin(2*pi*t)
        self.axis.plot(t,s)
        self.axis.set_xlabel('time (s)')
        self.axis.set_ylabel('voltage')

        self.canvas = FigureCanvas(self.figure) # a gtk.DrawingArea
        self.canvas.show()
        self.canvas.set_size_request(600, 400)
        self.canvas.set_events(
            gtk.gdk.BUTTON_PRESS_MASK      |            
            gtk.gdk.KEY_PRESS_MASK      |
            gtk.gdk.KEY_RELEASE_MASK    
            )
        self.canvas.set_flags(gtk.HAS_FOCUS|gtk.CAN_FOCUS)
        self.canvas.grab_focus()

        def keypress(widget, event):
            print 'key press'
        def buttonpress(widget, event):
            print 'button press'

        self.canvas.connect('key_press_event', keypress)
        self.canvas.connect('button_press_event', buttonpress)      

        def onselect(xmin, xmax):
            print xmin, xmax

        span = HorizontalSpanSelector(self.axis, onselect, useblit=False,
                                          rectprops=dict(alpha=0.5, facecolor='red') )


        self['vboxMain'].pack_start(self.canvas, True, True)
        self['vboxMain'].show()
        
        # below is optional if you want the navigation toolbar
        self.navToolbar = NavigationToolbar(self.canvas, self['windowMain'])
        self.navToolbar.lastDir = '/var/tmp/'
        self['vboxMain'].pack_start(self.navToolbar)
        self.navToolbar.show()

        sep = gtk.HSeparator()
        sep.show()
        self['vboxMain'].pack_start(sep, True, True)


        self['vboxMain'].reorder_child(self['buttonClickMe'],-1)
示例#27
0
    def __init__(self):
        self.widgets = gtk.glade.XML('mpl_with_glade.glade')
        self.widgets.signal_autoconnect(GladeHandlers.__dict__)

        self['windowMain'].connect('destroy', lambda x: gtk.main_quit())
        self['windowMain'].move(10, 10)
        self.figure = Figure(figsize=(8, 6), dpi=72)
        self.axis = self.figure.add_subplot(111)

        t = arange(0.0, 3.0, 0.01)
        s = sin(2 * pi * t)
        self.axis.plot(t, s)
        self.axis.set_xlabel('time (s)')
        self.axis.set_ylabel('voltage')

        self.canvas = FigureCanvas(self.figure)  # a gtk.DrawingArea
        self.canvas.show()
        self.canvas.set_size_request(600, 400)
        self.canvas.set_events(gtk.gdk.BUTTON_PRESS_MASK
                               | gtk.gdk.KEY_PRESS_MASK
                               | gtk.gdk.KEY_RELEASE_MASK)
        self.canvas.set_flags(gtk.HAS_FOCUS | gtk.CAN_FOCUS)
        self.canvas.grab_focus()

        def keypress(widget, event):
            print 'key press'

        def buttonpress(widget, event):
            print 'button press'

        self.canvas.connect('key_press_event', keypress)
        self.canvas.connect('button_press_event', buttonpress)

        def onselect(xmin, xmax):
            print xmin, xmax

        span = HorizontalSpanSelector(self.axis,
                                      onselect,
                                      useblit=False,
                                      rectprops=dict(alpha=0.5,
                                                     facecolor='red'))

        self['vboxMain'].pack_start(self.canvas, True, True)
        self['vboxMain'].show()

        # below is optional if you want the navigation toolbar
        self.navToolbar = NavigationToolbar(self.canvas, self['windowMain'])
        self.navToolbar.lastDir = '/var/tmp/'
        self['vboxMain'].pack_start(self.navToolbar)
        self.navToolbar.show()

        sep = gtk.HSeparator()
        sep.show()
        self['vboxMain'].pack_start(sep, True, True)

        self['vboxMain'].reorder_child(self['buttonClickMe'], -1)
def gaussian_example():
    """Create graph with 4 gaussian distributions"""

    x = nx.arange(-4, 4, 0.01)
    list_sigma = [0.2, 0.5, 1, 2]
    for sigma in list_sigma:
        y = normpdf(x, 0, sigma)  # unit normal
        p.plot(x, y, lw=2)
    p.legend(["$\sigma = %s$" % s for s in list_sigma])
    p.title("Normal Gaussian Distribution")
    p.savefig("results/gaussian.png")  # Save graph
示例#29
0
 def _parse_args(self, *args):
     X, Y, U, V, C = [None]*5
     args = list(args)
     if len(args) == 3 or len(args) == 5:
         C = nx.ravel(args.pop(-1))
         #print 'in parse_args, C:', C
     V = nx.ma.asarray(args.pop(-1))
     U = nx.ma.asarray(args.pop(-1))
     nn = nx.shape(U)
     nc = nn[0]
     nr = 1
     if len(nn) > 1:
         nr = nn[1]
     if len(args) == 2:
         X, Y = [nx.ravel(a) for a in args]
         if len(X) == nc and len(Y) == nr:
             X, Y = [nx.ravel(a) for a in meshgrid(X, Y)]
     else:
         X, Y = [nx.ravel(a) for a in meshgrid(nx.arange(nc), nx.arange(nr))]
     return X, Y, U, V, C
示例#30
0
    def __init__(self):
        QtCore.QObject.__init__(self, None)

        self.ax = p.subplot(111)
        self.canvas = self.ax.figure.canvas
        self.cnt = 0

        # create the initial line
        self.x = nx.arange(0, 2 * nx.pi, 0.01)
        self.line, = p.plot(self.x, nx.sin(self.x), animated=True, lw=2)

        self.background = None
示例#31
0
    def __init__(self):
        QtCore.QObject.__init__(self, None)

        self.ax = p.subplot(111)
        self.canvas = self.ax.figure.canvas
        self.cnt = 0
        
        # create the initial line
        self.x = nx.arange(0,2*nx.pi,0.01)
        self.line, = p.plot(self.x, nx.sin(self.x), animated=True, lw=2)
        
        self.background = None
示例#32
0
 def plot3d(self):
     # sample taken from http://www.scipy.org/Cookbook/Matplotlib/mplot3D
     ax3d = matplotlib.axes3d.Axes3D(self.fig)
     plt = self.fig.axes.append(ax3d)
     
     delta = nx.pi / 199.0
     u = nx.arange(0, 2*nx.pi+(delta*2), delta*2)
     v = nx.arange(0, nx.pi+delta, delta)
     
     x=nx.outerproduct(nx.cos(u),nx.sin(v))
     y=nx.outerproduct(nx.sin(u),nx.sin(v))
     z=nx.outerproduct(nx.ones(nx.size(u)), nx.cos(v))
     print x.shape, y.shape, z.shape
     
     #ax3d.plot_wireframe(x,y,z)
     surf = ax3d.plot_surface(x, y, z)
     surf.set_array(matplotlib.mlab.linspace(0, 1.0, len(v)))
     
     ax3d.set_xlabel('X')
     ax3d.set_ylabel('Y')
     ax3d.set_zlabel('Z')
     self.fig.savefig('globe')
示例#33
0
 def plot_data(self):
     # Use ths line if using a toolbar
     a = self.fig.add_subplot(111)
     
     # Or this one if there is no toolbar
     #a = Subplot(self.fig, 111)
     
     t = numpy.arange(0.0,3.0,0.01)
     s = numpy.sin(2*numpy.pi*t)
     c = numpy.cos(2*numpy.pi*t)
     a.plot(t,s)
     a.plot(t,c)
     self.toolbar.update()
示例#34
0
    def plot3d(self):
        # sample taken from http://www.scipy.org/Cookbook/Matplotlib/mplot3D
        ax3d = matplotlib.axes3d.Axes3D(self.fig)
        plt = self.fig.axes.append(ax3d)

        delta = nx.pi / 199.0
        u = nx.arange(0, 2 * nx.pi + (delta * 2), delta * 2)
        v = nx.arange(0, nx.pi + delta, delta)

        x = nx.outerproduct(nx.cos(u), nx.sin(v))
        y = nx.outerproduct(nx.sin(u), nx.sin(v))
        z = nx.outerproduct(nx.ones(nx.size(u)), nx.cos(v))
        print x.shape, y.shape, z.shape

        #ax3d.plot_wireframe(x,y,z)
        surf = ax3d.plot_surface(x, y, z)
        surf.set_array(matplotlib.mlab.linspace(0, 1.0, len(v)))

        ax3d.set_xlabel('X')
        ax3d.set_ylabel('Y')
        ax3d.set_zlabel('Z')
        self.fig.savefig('globe')
示例#35
0
def pplot(path, x, text):
    # N = float(len(x))
    x = sorted([float(item) for item in x])
    # ------------------ liberated from scipy.stats.morestats ------------------
    N = len(x)
    Ui = np.zeros(N) * 1.0
    Ui[-1] = 0.5 ** (1.0 / N)
    Ui[0] = 1 - Ui[-1]
    i = arange(2, N)
    Ui[1:-1] = (i - 0.3175) / (N + 0.365)
    y = stats.norm.ppf(Ui)
    ## -------------------------------------------------------------------------
    regressionplot(path, x, y, text, "Normal Score", pi=True)
示例#36
0
    def plot_data(self):
        # Use ths line if using a toolbar
        a = self.figmgr.add_subplot(111)

        # Or this one if there is no toolbar
        #a = Subplot(self.fig, 111)

        t = numpy.arange(0.0, 3.0, 0.01)
        s = numpy.sin(2 * numpy.pi * t)
        c = numpy.cos(2 * numpy.pi * t)
        a.plot(t, s)
        a.plot(t, c)
        self.toolbar.update()
示例#37
0
    def OnButton(self, evt):
        """
        """
        dd = 20
        t = arange(0.0, 3.0, 1.0 / dd)
        s = [10 + y * y / dd + self.count for y in xrange(0, 3 * dd)]
        self.count += 5
        self.axes.lines.pop(0)

        line, = self.axes.plot(t, s, 'r:d')
        line.set_markersize(5)
        self.Refresh()
        evt.Skip()
示例#38
0
    def __init__(self):
        gtk.Window.__init__(self,gtk.WINDOW_TOPLEVEL)

        self.set_title("MixedEmotions")
        self.set_border_width(10)
        
        self.fig = Figure(figsize=(3,1), dpi=100)
        self.ax = self.fig.add_subplot(111)
        self.x = arange(0,2*pi,0.01)           # x-array
        self.lines = self.ax.plot(self.x,sin(self.x))
        self.canvas = FigureCanvas(self.fig)
        self.add(self.canvas)      

        self.figcount = 0
        gtk.timeout_add(100, self.updatePlot)
示例#39
0
    def draw(self):
        if not hasattr(self, 'subplot'):
            self.subplot = self._figure.add_subplot(111)

        theta = arange(0, 45*2*pi, 0.02)
        rad = (0.8*theta/(2*pi)+1)
        r = rad*(8 + sin(theta*7+rad/1.8))
        x = r*cos(theta)
        y = r*sin(theta)
        #Now draw it
        self.subplot.plot(x,y, '-r')
        #Set some plot attributes
        self.subplot.set_title("A polar flower (%s points)"%len(x), fontsize = 12)
        self.subplot.set_xlabel("test plot", fontsize = 8)
        self.subplot.set_xlim([-400, 400])
        self.subplot.set_ylim([-400, 400])
示例#40
0
def _create_plot(self):
        from matplotlib.figure import Figure
        from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas
        from matplotlib.numerix import arange, sin, pi

        figure = Figure(figsize=(5, 4), dpi=100)
        canvas = FigureCanvas(figure)  # a gtk.DrawingArea
        #win.add(canvas)

        axes = figure.add_subplot(111)
        x = arange(0.0, 30.0, 0.01)
        y = sin(2 * pi * x)
        line, = axes.plot(x, y)
        axes.set_title('hi mom')
        axes.grid(True)
        axes.set_xlabel('time')
        axes.set_ylabel('volts')
示例#41
0
    def __init__(self, parent, id, title, analyse_size):
        self.width, self.height = analyse_size
        wx.Frame.__init__(self, parent, id, title, style=wx.DEFAULT_FRAME_STYLE & ~(wx.RESIZE_BORDER | wx.RESIZE_BOX | wx.MAXIMIZE_BOX))

        self.SetBackgroundColour(wx.NamedColor("WHITE"))

        self.figure = Figure(figsize=(5, 4), dpi=100)
        self.axes = self.figure.add_subplot(111)
        t = arange(0.0, 3.0, 0.01)
        s = sin(2*pi*t)
        
        self.axes.plot(t, s)

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

        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.canvas, 1, wx.TOP | wx.LEFT | wx.EXPAND)

        # Capture the paint message
#        EVT_PAINT(self, self.OnPaint)        

#        self.toolbar = MyNavigationToolbar(self.canvas, True)
#        self.toolbar.Realize()
#        if wx.Platform == '__WXMAC__':
#            # Mac platform (OSX 10.3, MacPython) does not seem to cope with
#            # having a toolbar in a sizer. This work-around gets the buttons
#            # back, but at the expense of having the toolbar at the top
#            self.SetToolBar(self.toolbar)
#        else:
#            # On Windows platform, default window size is incorrect, so set
#            # toolbar width to figure width.
#            tw, th = self.toolbar.GetSizeTuple()
#            fw, fh = self.canvas.GetSizeTuple()
#            # By adding toolbar in sizer, we are able to put it at the bottom
#            # of the frame - so appearance is closer to GTK version.
#            # As noted above, doesn't work for Mac.
#            self.toolbar.SetSize(wxSize(fw, th))
#            self.sizer.Add(self.toolbar, 0, wxLEFT | wxEXPAND)
#
#        # update the axes menu on the toolbar
#        self.toolbar.update()

        self.Bind(wx.EVT_CLOSE, self.OnClose)

        self.SetSizer(self.sizer)
        self.Fit()
示例#42
0
 def __init__( self, strengthRange, ax, pos, decay_time=2 ) :
     
   n = 25
   t = arange(n)*2*pi/n
   self.disc = array([(cos(x),sin(x)) for x in t])
   self.strength = 0
   self.pos = pos
   self.offset = (279, 157)
   self.scale = 1.35
   self.max_size = 5 #0.5
   self.min_size = 0.10 #0.05
   self.size = self.min_size
   self.color = '#ff8000'
   self.decay_time = decay_time
   self.strengthRange = strengthRange
   self.t0 = 0
   v = self.disc * self.size + self.pos
   self.poly = ax.fill( v[:,0], v[:,1], self.color )
示例#43
0
    def __init__(self):
        wxFrame.__init__(self, None, -1, 'CanvasFrame', size=(550, 350))

        self.SetBackgroundColour(wxNamedColor("WHITE"))

        self.figure = Figure(figsize=(5, 4), dpi=100)
        self.axes = self.figure.add_subplot(111)
        t = arange(0.0, 3.0, 0.01)
        s = sin(2 * pi * t)

        self.axes.plot(t, s)

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

        self.sizer = wxBoxSizer(wxVERTICAL)
        self.sizer.Add(self.canvas, 1, wxTOP | wxLEFT | wxEXPAND)
        # Capture the paint message
        EVT_PAINT(self, self.OnPaint)
示例#44
0
文件: axes.py 项目: yingjun2/codenode
    def _find_axes(self, minval, maxval):
        """
        Try to find axis tick positions that are well spaced
        """
        if minval >= maxval:
            raise ValueError, "maxval >= minval is required"

        # If there is a small differences between max and min values 
        # compared to the size of the largest of (abs(maxval), abs(minval))
        # the function 'tasteless_ticks' is used, which in common usage is rare.
        if (abs((maxval - minval)/float(max(abs(maxval),abs(minval)))) < 0.2):
            tslmajor, oppaxis, step = self._tasteless_ticks(minval, maxval, 10)
        else:
            tslmajor, oppaxis, step = self._tasteful_ticks(minval, maxval)
        min = tslmajor[0] - step
        tslminor = list(arange(min, maxval + 0.2*step, 0.2*step))
        tslminor = self._in_range(tslminor, minval, maxval)
        return oppaxis, step, tslminor, tslmajor 
示例#45
0
 def draw(self):
     if not hasattr(self, 'subplot'):
         self.subplot = self.figure.add_subplot(111)
     theta = arange(0, 45 * 2 * pi, 0.02)
     rad = (0.8 * theta / (2 * pi) + 1)
     r = rad * (8 + sin(theta * 7 + rad / 1.8))
     x = r * cos(theta)
     y = r * sin(theta)
     #Now draw it
     self.subplot.plot(x, y, '-r')
     #Set some plot attributes
     self.subplot.set_title("A polar flower (%s points)" % len(x),
                            fontsize=12)
     self.subplot.set_xlabel(
         "Flower is from  http://www.physics.emory.edu/~weeks/ideas/rose.html",
         fontsize=8)
     self.subplot.set_xlim([-400, 400])
     self.subplot.set_ylim([-400, 400])
示例#46
0
文件: axes.py 项目: knoboo/knoboo
    def _find_axes(self, minval, maxval):
        """
        Try to find axis tick positions that are well spaced
        """
        if minval >= maxval:
            raise ValueError, "maxval >= minval is required"

        # If there is a small differences between max and min values 
        # compared to the size of the largest of (abs(maxval), abs(minval))
        # the function 'tasteless_ticks' is used, which in common usage is rare.
        if (abs((maxval - minval)/float(max(abs(maxval),abs(minval)))) < 0.2):
            tslmajor, oppaxis, step = self._tasteless_ticks(minval, maxval, 10)
        else:
            tslmajor, oppaxis, step = self._tasteful_ticks(minval, maxval)
        min = tslmajor[0] - step
        tslminor = list(arange(min, maxval + 0.2*step, 0.2*step))
        tslminor = self._in_range(tslminor, minval, maxval)
        return oppaxis, step, tslminor, tslmajor 
示例#47
0
 def _h_arrows(self, length):
     ''' length is in arrow width units '''
     minsh = self.minshaft * self.headlength
     N = len(length)
     length = nx.reshape(length, (N,1))
     x = nx.array([0, -self.headaxislength,
                     -self.headlength, 0], nx.Float64)
     x = x + nx.array([0,1,1,1]) * length
     y = 0.5 * nx.array([1, 1, self.headwidth, 0], nx.Float64)
     y = nx.repeat(y[nx.newaxis,:], N)
     x0 = nx.array([0, minsh-self.headaxislength,
                     minsh-self.headlength, minsh], nx.Float64)
     y0 = 0.5 * nx.array([1, 1, self.headwidth, 0], nx.Float64)
     ii = [0,1,2,3,2,1,0]
     X = nx.take(x, ii, 1)
     Y = nx.take(y, ii, 1)
     Y[:, 3:] *= -1
     X0 = nx.take(x0, ii)
     Y0 = nx.take(y0, ii)
     Y0[3:] *= -1
     shrink = length/minsh
     X0 = shrink * X0[nx.newaxis,:]
     Y0 = shrink * Y0[nx.newaxis,:]
     short = nx.repeat(length < minsh, 7, 1)
     #print 'short', length < minsh
     X = nx.where(short, X0, X)
     Y = nx.where(short, Y0, Y)
     if self.pivot[:3] == 'mid':
         X -= 0.5 * X[:,3, nx.newaxis]
     elif self.pivot[:3] == 'tip':
         X = X - X[:,3, nx.newaxis]   #numpy bug? using -= does not
                                      # work here unless we multiply
                                      # by a float first, as with 'mid'.
     tooshort = length < self.minlength
     if nx.any(tooshort):
         th = nx.arange(0,7,1, nx.Float64) * (nx.pi/3.0)
         x1 = nx.cos(th) * self.minlength * 0.5
         y1 = nx.sin(th) * self.minlength * 0.5
         X1 = nx.repeat(x1[nx.newaxis, :], N, 0)
         Y1 = nx.repeat(y1[nx.newaxis, :], N, 0)
         tooshort = nx.repeat(tooshort, 7, 1)
         X = nx.where(tooshort, X1, X)
         Y = nx.where(tooshort, Y1, Y)
     return X, Y
示例#48
0
    def createProjectGraph(self, widget):

        while True:
            try:
                # empty axis if neccesary, and reset title and stuff
                self.axis.clear()
                self.axis.set_xlabel('Yepper')
                self.axis.set_ylabel('Flabber')
                self.axis.set_title('A Graph')
                self.axis.grid(True)

                # get data
                age = self.wTree.get_widget("entry2").get_text()
                size = self.wTree.get_widget("entry3").get_text()
                age != ""
                size != ""

                N = 1
                ind = arange(N)  # the x locations for the groups
                width = 0.35  # the width of the bars

                p1 = self.axis.bar(ind, int(age), width, color='r')
                p2 = self.axis.bar(ind + width, int(size), width, color='y')

                self.axis.legend((p1[0], p2[0]), ("Age", "Size"), shadow=True)
                #self.axis.set_xticks(ind+width, ('G1') )
                self.axis.set_xlim(-width, len(ind))

                self.canvas.destroy()
                self.canvas = FigureCanvasGTK(self.figure)  # a gtk.DrawingArea
                self.canvas.show()
                self.grahview = self.wTree.get_widget("vbox1")
                self.grahview.pack_start(self.canvas, True, True)
                break

            except ValueError:
                self.wDialog = gtk.glade.XML("project2.glade",
                                             "cannotCreateProjGraph")
                close = self.wDialog.get_widget("cannotCreateProjGraph")
                response = close.run()
                if response == gtk.RESPONSE_OK:
                    close.destroy()
                break
示例#49
0
    def __init__(self):
        wxFrame.__init__(self,None,-1,
                         'CanvasFrame',size=(550,350))

        self.SetBackgroundColour(wxNamedColor("WHITE"))

        self.figure = Figure(figsize=(5,4), dpi=100)
        self.axes = self.figure.add_subplot(111)
        t = arange(0.0,3.0,0.01)
        s = sin(2*pi*t)
        
        self.axes.plot(t,s)

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

        self.sizer = wxBoxSizer(wxVERTICAL)
        self.sizer.Add(self.canvas, 1, wxTOP | wxLEFT | wxEXPAND)
        # Capture the paint message        
        EVT_PAINT(self, self.OnPaint)        
示例#50
0
    def __init__(self):
        wxFrame.__init__(self, None, -1, 'CanvasFrame', size=(550, 350))

        self.SetBackgroundColour(wxNamedColor("WHITE"))

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

        self.axes.plot(t, s)
        self.canvas = FigureCanvas(self, -1, self.figure)

        self.sizer = wxBoxSizer(wxVERTICAL)
        self.sizer.Add(self.canvas, 1, wxLEFT | wxTOP | wxGROW)
        self.SetSizer(self.sizer)
        self.Fit()

        self.add_toolbar()  # comment this out for no toolbar
示例#51
0
 def OnInit(self):
     from matplotlib.numerix import arange, sin, pi, cos
     'Create the main window and insert the custom frame'
     x = arange(0.0,3.0,0.01)
     s = sin(2*pi*x)
     c = cos(2*pi*x)
     t = sin(2*pi*x) + cos(2*pi*x)
     frame = ExtendedPlotFrame(None)
     style = {'with':'lines', 'color':'blue','line':'solid','width':2}
     style['legend'] = 'sin(x)'
     frame.insertCurve(x,s, style)
     style = {'with':'lines', 'color':'red','line':'solid','width':2}
     style['legend'] = 'cos(x)'
     frame.insertCurve(x,c, style)
     style = {'with':'lines', 'color':'black','line':'solid','width':2}
     #style['legend'] = 'sin(x)+cos(x)'
     frame.insertCurve(x,t, style)
     frame.Show(True)
     return True
示例#52
0
    def __init__(self):
        wxFrame.__init__(self, None, -1, "CanvasFrame", size=(550, 350))

        self.SetBackgroundColour(wxNamedColor("WHITE"))

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

        self.axes.plot(t, s)
        self.canvas = FigureCanvas(self, -1, self.figure)

        self.sizer = wxBoxSizer(wxVERTICAL)
        self.sizer.Add(self.canvas, 1, wxLEFT | wxTOP | wxGROW)
        self.SetSizer(self.sizer)
        self.Fit()

        self.add_toolbar()  # comment this out for no toolbar
示例#53
0
def test_matplotlib(request) :
    # Generate and plot some simple data:
    x = N.arange(0, 2*N.pi, 0.1)
    y = N.sin(x)+1

    pylab.ylim(8,0)
    pylab.plot(y,x)
    F = pylab.gcf()

    # Now check everything with the defaults:
    DPI = F.get_dpi()    
    DefaultSize = F.get_size_inches()
    F.set_size_inches( (2, 5) )
    filename = settings.MEDIA_ROOT + '/images/test1.png'
    F.savefig(filename)
     
    data = simplejson.dumps({'filename': filename})   
    
    return HttpResponse(data, mimetype="application/javascript")
示例#54
0
    def __init__(self):
        wxFrame.__init__(self, None, -1, 'CanvasFrame', size=(550, 350))

        self.SetBackgroundColour(wxNamedColor("WHITE"))

        self.figure = Figure(figsize=(5, 4), dpi=100)
        self.axes = self.figure.add_subplot(111)
        t = arange(0.0, 3.0, 0.01)
        s = sin(2 * pi * t)

        self.axes.plot(t, s)

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

        self.sizer = wxBoxSizer(wxVERTICAL)
        self.sizer.Add(self.canvas, 1, wxTOP | wxLEFT | wxEXPAND)
        # Capture the paint message
        EVT_PAINT(self, self.OnPaint)

        self.toolbar = MyNavigationToolbar(self.canvas, True)
        self.toolbar.Realize()
        if wxPlatform == '__WXMAC__':
            # Mac platform (OSX 10.3, MacPython) does not seem to cope with
            # having a toolbar in a sizer. This work-around gets the buttons
            # back, but at the expense of having the toolbar at the top
            self.SetToolBar(self.toolbar)
        else:
            # On Windows platform, default window size is incorrect, so set
            # toolbar width to figure width.
            tw, th = self.toolbar.GetSizeTuple()
            fw, fh = self.canvas.GetSizeTuple()
            # By adding toolbar in sizer, we are able to put it at the bottom
            # of the frame - so appearance is closer to GTK version.
            # As noted above, doesn't work for Mac.
            self.toolbar.SetSize(wxSize(fw, th))
            self.sizer.Add(self.toolbar, 0, wxLEFT | wxEXPAND)

        # update the axes menu on the toolbar
        self.toolbar.update()
        self.SetSizer(self.sizer)
        self.Fit()
示例#55
0
文件: axes.py 项目: yingjun2/codenode
    def _tasteless_ticks(self, minval, maxval, num_pieces):
        minval0 = minval
        maxval0 = maxval
        rnd   = int(floor(log(maxval - minval)/log(10)))
        if rnd < 0:
            rnd -= 1

        step  = (maxval - minval)/float(num_pieces)
        minval = self._trunc(minval, rnd)
        maxval = self._trunc(maxval + step, rnd)

        step  = (maxval - minval)/float(num_pieces)
        tslmajor = list(arange(minval, minval+(num_pieces+1)*step, step))
        tslmajor = self._in_range(tslmajor, minval0, maxval0)

        oppaxis = 0
        if maxval <= 0:  # only negative
            oppaxis = tslmajor[-1]
        elif minval >= 0:
            oppaxis = tslmajor[0]
            
        return tslmajor, oppaxis, step
示例#56
0
    def createDBGraph(self, widget):
        self.axis.clear()
        self.axis.set_xlabel('Samples (n)')
        self.axis.set_ylabel('Value (-)')
        self.axis.set_title(
            'Another Graph (click on the columnheader to sort)')
        self.axis.grid(True)

        # get columns from listmodel
        age = []
        for row in self.listmodel:
            age.append(row[1])
        size = []
        for row in self.listmodel:
            size.append(row[2])

        # get number of rows
        N = len(age)

        ind = arange(N)  # the x locations for the groups
        width = 0.35  # the width of the bars
        p1 = self.axis.bar(ind, age, width, color='b')
        p2 = self.axis.bar(ind + width, size, width, color='r')
        # destroy graph if it already exists
        while True:
            try:
                self.canvas2.destroy()
                break
            except:
                print "nothing to destroy"
                break

        self.canvas2 = FigureCanvasGTK(self.figure)  # a gtk.DrawingArea
        self.canvas2.show()
        self.grahview = self.wTree.get_widget("vbox2")
        self.grahview.pack_start(self.canvas2, True, True)
示例#57
0
 def do_capzone(self,event):
     setActiveWindow()
     if event.button==1:
         if event.inaxes is not None:
             x,y = event.xdata, event.ydata
             xw,yw,rw,well_layers = findWell(x,y)
             Ntraces_capzone = getTrace('ncap')
             alpha = arange(0,2*pi-1e-6,(2*pi)/Ntraces_capzone)
             step = getTrace('step'); tmax = getTrace('tmax'); nmax = getTrace('nmax')
             elev = getTrace('elev'); layers = getTrace('layers'); forward = getTrace('capzoneforward')
             elev = eval( '['+elev+']' )
             win = getActiveWindow()
             step = step * ( win[2] - win[0] )
             step = -step
             if forward: step = -step
             zr = []
             zt,zb = getLayerTopBottom(xw,yw)
             for i in range(len(well_layers)):
                 for j in range(len(elev)):
                     zr.append( zb[well_layers[i]-1] + elev[j] * (zt[well_layers[i]-1]-zb[well_layers[i]-1]) )
             for i in range(Ntraces_capzone):
                 xr = [ xw + 2*rw*cos(alpha[i]) ]  ; yr = [ yw + 2*rw*sin(alpha[i]) ]
                 xr = len(zr)*xr; yr = len(zr)*yr;
                 doTracelines(xr,yr,zr,step,tmax,nmax)