def Ellipse_Point(self, alpha=0): #PointClass(0,0) #große Halbachse, kleine Halbachse, rotation der Ellipse (rad), Winkel des Punkts in der Ellipse (rad) Ex = self.a * cos(alpha) * cos( self.rotation) - self.b * sin(alpha) * sin(self.rotation) Ey = self.a * cos(alpha) * sin( self.rotation) + self.b * sin(alpha) * cos(self.rotation) return PointClass(self.center.x + Ex, self.center.y + Ey)
def calc_point(self, phi=0.0, rotation=0.0): #PointClass(0,0),Radius #große Halbachse, kleine Halbachse, rotation der Ellipse (rad), Winkel des Punkts in der Ellipse (rad) Ex = self.De * cos(phi) * cos(rotation) - self.de * sin(phi) * sin( rotation) + self.vers_d * cos(rotation) Ey = self.De * cos(phi) * sin(rotation) + self.de * sin(phi) * cos( rotation) + self.vers_d * sin(rotation) Radius = sqrt(Ex**2 + Ey**2) return PointClass(Ex, Ey), Radius
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
def calc_O1_O2_k(self,r1,r2,tan_a,teta): #print("r1: %0.3f, r2: %0.3f, tan_a: %0.3f, teta: %0.3f" %(r1,r2,tan_a,teta)) #print("N1: x: %0.3f, y: %0.3f" %(-sin(tan_a), cos(tan_a))) #print("V: x: %0.3f, y: %0.3f" %(-sin(teta+tan_a),cos(teta+tan_a))) O1=PointClass(x=self.Pa.x-r1*sin(tan_a),\ y=self.Pa.y+r1*cos(tan_a)) k=PointClass(x=self.Pa.x+r1*(-sin(tan_a)+sin(teta+tan_a)),\ y=self.Pa.y+r1*(cos(tan_a)-cos(tan_a+teta))) O2=PointClass(x=k.x+r2*(-sin(teta+tan_a)),\ y=k.y+r2*(cos(teta+tan_a))) return O1, O2, k
def calc_O1_O2_k(self, r1, r2, tan_a, teta): #print("r1: %0.3f, r2: %0.3f, tan_a: %0.3f, teta: %0.3f" %(r1,r2,tan_a,teta)) #print("N1: x: %0.3f, y: %0.3f" %(-sin(tan_a), cos(tan_a))) #print("V: x: %0.3f, y: %0.3f" %(-sin(teta+tan_a),cos(teta+tan_a))) O1=PointClass(x=self.Pa.x-r1*sin(tan_a),\ y=self.Pa.y+r1*cos(tan_a)) k=PointClass(x=self.Pa.x+r1*(-sin(tan_a)+sin(teta+tan_a)),\ y=self.Pa.y+r1*(cos(tan_a)-cos(tan_a+teta))) O2=PointClass(x=k.x+r2*(-sin(teta+tan_a)),\ y=k.y+r2*(cos(teta+tan_a))) return O1, O2, k
def calc_std_parameters(self): #Berechnung der langen Seite der Ellipse self.De1=self.dm*sin(radians(180)-self.a1)/(2*sin(self.a1-self.a2)) self.De2=self.dm*sin(self.a1)/(2*sin(radians(180)-self.a1-self.a2)) self.De=self.De1+self.De2 #Berechnung des Versatzes von der Mittellinie self.vers=(self.De2-(self.De/2)) self.vers_h=self.vers*sin(self.a2) self.vers_d=self.vers*cos(self.a2) #Berechnung der kurzen Seite der Ellipse self.dmv=self.dm-2*self.vers_h/tan(self.a1) self.de=2*sqrt((self.dmv/2)**2-(self.vers_d/2)**2)
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
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)
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)
def update_line(*args): global blit_time if update_line.background is None: update_line.background = canvas.copy_from_bbox(ax.bbox) # restore the clean slate background canvas.restore_region(update_line.background) # update the data line.set_ydata(nx.sin(x + update_line.cnt / 10.0)) # just draw the animated artist ax.draw_artist(line) # just redraw the axes rectangle t = time.time() canvas.blit(ax.bbox) blit_time += time.time() - t if update_line.cnt == 200: # print the timing info and quit frame_time = time.time() - tstart print '200 frames: %.2f seconds' % frame_time print '200 blits: %.2f seconds' % blit_time print print 'FPS: %.2f' % (200 / frame_time) print 'BPS: %.2f' % (200 / blit_time) sys.exit() update_line.cnt += 1 wx.WakeUpIdle()
def calc_std_parameters(self): #Berechnung der langen Seite der Ellipse self.De1 = self.dm * sin(radians(180) - self.a1) / (2 * sin(self.a1 - self.a2)) self.De2 = self.dm * sin( self.a1) / (2 * sin(radians(180) - self.a1 - self.a2)) self.De = self.De1 + self.De2 #Berechnung des Versatzes von der Mittellinie self.vers = (self.De2 - (self.De / 2)) self.vers_h = self.vers * sin(self.a2) self.vers_d = self.vers * cos(self.a2) #Berechnung der kurzen Seite der Ellipse self.dmv = self.dm - 2 * self.vers_h / tan(self.a1) self.de = 2 * sqrt((self.dmv / 2)**2 - (self.vers_d / 2)**2)
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
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()
def update_line(*args): global blit_time if update_line.background is None: update_line.background = canvas.copy_from_bbox(ax.bbox) # restore the clean slate background canvas.restore_region(update_line.background) # update the data line.set_ydata(nx.sin(x+update_line.cnt/10.0)) # just draw the animated artist ax.draw_artist(line) # just redraw the axes rectangle t = time.time() canvas.blit(ax.bbox) blit_time += time.time() - t if update_line.cnt==1000: # print the timing info and quit frame_time = time.time() - tstart print '200 frames: %.2f seconds' % frame_time print '200 blits: %.2f seconds' % blit_time print print 'FPS: %.2f' % (1000/frame_time) print 'BPS: %.2f' % (1000/blit_time) sys.exit() update_line.cnt += 1 wx.WakeUpIdle()
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)
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])
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)
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
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])
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
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 __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 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
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')
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')
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
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
def plot2plot(self, plot): x=[]; y=[] #Alle 6 Grad ein Linien Segment Drucken segments=int((abs(degrees(self.ext))//6)+1) for i in range(segments+1): ang=self.s_ang+i*self.ext/segments x.append(self.O.x+cos(ang)*abs(self.r)) y.append(self.O.y+sin(ang)*abs(self.r)) plot.plot(x,y,'-g') #plot.plot([x[0],x[-1]],[y[0],y[-1]],'cd') plot.plot([self.Pa.x,self.Pe.x],[self.Pa.y,self.Pe.y],'cd')
def calc_r1_r2(self, l, alpha, beta, teta): #print("alpha: %s, beta: %s, teta: %s" %(alpha,beta,teta)) r1 = (l / (2 * sin((alpha + beta) / 2)) * sin( (beta - alpha + teta) / 2) / sin(teta / 2)) r2 = (l / (2 * sin((alpha + beta) / 2)) * sin( (2 * alpha - teta) / 2) / sin((alpha + beta - teta) / 2)) return r1, r2
def OnWhiz(self, evt): self.x += numerix.pi / 15 self.y += numerix.pi / 20 z = numerix.sin(self.x) + numerix.cos(self.y) self.im.set_array(z) 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[0].set_data(xmax_i, ymax_i) self.canvas.draw()
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')
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()
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')
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')
def plot2plot(self, plot): x = [] y = [] #Alle 6 Grad ein Linien Segment Drucken segments = int((abs(degrees(self.ext)) // 6) + 1) for i in range(segments + 1): ang = self.s_ang + i * self.ext / segments x.append(self.O.x + cos(ang) * abs(self.r)) y.append(self.O.y + sin(ang) * abs(self.r)) plot.plot(x, y, '-g') #plot.plot([x[0],x[-1]],[y[0],y[-1]],'cd') plot.plot([self.Pa.x, self.Pe.x], [self.Pa.y, self.Pe.y], 'cd')
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()
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')
def OnWhiz(self,evt): self.x += numerix.pi/15 self.y += numerix.pi/20 z = numerix.sin(self.x) + numerix.cos(self.y) self.im.set_array(z) zmax = mlab.max(mlab.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[0].set_data(xmax_i,ymax_i) self.canvas.draw()
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)
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
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()
def update_line(*args): # restore the clean slate background canvas.restore_region(background) # update the data line.set_ydata(nx.sin(x+update_line.cnt/10.0)) # just draw the animated artist ax.draw_artist(line) # just redraw the axes rectangle canvas.blit(ax.bbox) if update_line.cnt==50: # print the timing info and quit print 'FPS:' , update_line.cnt/(time.time()-tstart) sys.exit() update_line.cnt += 1 return True
def update_line(*args): # restore the clean slate background canvas.restore_region(background) # update the data line.set_ydata(nx.sin(x + update_line.cnt / 10.0)) # just draw the animated artist ax.draw_artist(line) # just redraw the axes rectangle canvas.blit(ax.bbox) if update_line.cnt == 50: # print the timing info and quit print 'FPS:', update_line.cnt / (time.time() - tstart) sys.exit() update_line.cnt += 1 return True
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')
def update(self,ptr): # restore the clean slate background if self.background is None: self.background = self.canvas.copy_from_bbox(self.ax.bbox) self.canvas.restore_region(self.background) # update the data line.set_ydata(nx.sin(x+self.cnt/10.0)) # just draw the animated artist self.ax.draw_artist(line) # just redraw the axes rectangle self.canvas.blit(ax.bbox) self.cnt+=1 if self.cnt==200: # print the timing info and quit print 'FPS:' , 200/(time.time()-self.tstart) sys.exit() return True
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 )
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)
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
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")
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
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)
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
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()
def timerEvent(self, evt): if self.background is None: self.background = self.canvas.copy_from_bbox(self.ax.bbox) # restore the clean slate background self.canvas.restore_region(self.background) # update the data self.line.set_ydata(nx.sin(self.x + self.cnt / 10.0)) # just draw the animated artist self.ax.draw_artist(self.line) # just redraw the axes rectangle self.canvas.blit(self.ax.bbox) if self.cnt == ITERS: # print the timing info and quit print "FPS:", ITERS / (time.time() - self.tstart) sys.exit() else: self.cnt += 1
def timerEvent(self, evt): if self.background is None: self.background = self.canvas.copy_from_bbox(self.ax.bbox) # restore the clean slate background self.canvas.restore_region(self.background) # update the data self.line.set_ydata(nx.sin(self.x+self.cnt/10.0)) # just draw the animated artist self.ax.draw_artist(self.line) # just redraw the axes rectangle self.canvas.blit(self.ax.bbox) if self.cnt==ITERS: # print the timing info and quit print 'FPS:' , ITERS/(time.time()-self.tstart) sys.exit() else: self.cnt += 1
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()
def run(*args): background = canvas.copy_from_bbox(ax.bbox) # for profiling tstart = time.time() while 1: # restore the clean slate background canvas.restore_region(background) # update the data line.set_ydata(nx.sin(x + run.cnt / 10.0)) # just draw the animated artist ax.draw_artist(line) # just redraw the axes rectangle canvas.blit(ax.bbox) if run.cnt == 1000: # print the timing info and quit print 'FPS:', 1000 / (time.time() - tstart) sys.exit() run.cnt += 1