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 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 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 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 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 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 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 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 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 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_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 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 _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 plot_data(self): a = self.subplot 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, c, 'r:o')
#!/usr/bin/env python """ pcolormesh uses a QuadMesh, a faster generalization of pcolor, but with some restrictions. """ from matplotlib.mlab import linspace, meshgrid import matplotlib.numerix as nx from pylab import figure,show import matplotlib.numerix.ma as ma from matplotlib import cm, colors n = 56 x = linspace(-1.5,1.5,n) X,Y = meshgrid(x,x); Qx = nx.cos(Y) - nx.cos(X) Qz = nx.sin(Y) + nx.sin(X) Qx = (Qx + 1.1) Z = nx.sqrt(X**2 + Y**2)/5; Z = (Z - nx.mlab.amin(Z)) / (nx.mlab.amax(Z) - nx.mlab.amin(Z)) # The color array can include masked values: Zm = ma.masked_where(nx.fabs(Qz) < 0.5*nx.mlab.amax(Qz), Z) fig = figure() ax = fig.add_subplot(121) ax.pcolormesh(Qx,Qz,Z) ax.set_title('Without masked values') ax = fig.add_subplot(122)
backends, and requires that you have tex and the other dependencies described at http://matplotlib.sf.net/matplotlib.texmanager.html properly installed on your system. The first time you run a script you will see a lot of output from tex and associated tools. The next time, the run may be silent, as a lot of the information is cached in ~/.tex.cache """ from matplotlib import rc from matplotlib.numerix import arange, cos, pi from pylab import figure, axes, plot, xlabel, ylabel, title, \ grid, savefig, show rc('text', usetex=True, dvipnghack=False) figure(1) ax = axes([0.1, 0.1, 0.8, 0.7]) t = arange(0.0, 1.0 + 0.01, 0.01) s = cos(2 * 2 * pi * t) + 2 plot(t, s) xlabel(r'time (s)') ylabel(r'voltage (mV)', fontsize=16) title( r"\TeX\ is Number $\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$!", fontsize=16) grid(True) savefig('tex_demo') show()
lowest.axesPatch.set_facecolor('green') pylab.setp(lowest,'xticks',[]) pylab.setp(lowest,'yticks',[]) # Now add some axes with real plots... a=fig.add_axes([0,0,1,1],label='a') labelax(a,'a') a.plot([1,2,3],[4,5,6],'r-') b=fig.add_axes([0,0,1,1],label='b') labelax(b,'b') theta = nx.arange(0,2*nx.pi,0.01) x = nx.cos(theta) y = nx.sin(theta) b.plot(x,y,'b-') b2=fig.add_axes([0,0,1,1],label='b2') labelax(b2,'b2') more_plots = 1 if more_plots: c=fig.add_axes([0,0,1,1],label='c') labelax(c,'c') d=fig.add_axes([0,0,1,1],label='d') labelax(d,'d')
def onTimer(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) self.canvas.draw()
''' import pylab as P from matplotlib import collections, axes, transforms from matplotlib.colors import colorConverter import matplotlib.numerix as N nverts = 50 npts = 100 # Make some spirals r = N.array(range(nverts)) theta = N.array(range(nverts)) * (2*N.pi)/(nverts-1) xx = r * N.sin(theta) yy = r * N.cos(theta) spiral = zip(xx,yy) # Make some offsets xo = P.randn(npts) yo = P.randn(npts) xyo = zip(xo, yo) # Make a list of colors cycling through the rgbcmyk series. colors = [colorConverter.to_rgba(c) for c in ('r','g','b','c','y','m','k')] fig = P.figure() a = fig.add_subplot(2,2,1) col = collections.LineCollection([spiral], offsets=xyo, transOffset=a.transData)
# Often one wants to plot many signals over one another. There are a few # ways to do this. The naive implementation is just to add a constant # offset to each signal: # # <codecell> from pylab import plot, show, ylim, yticks from matplotlib.numerix import sin, cos, exp, pi, arange t = arange(0.0, 2.0, 0.01) s1 = sin(2*pi*t) s2 = exp(-t) s3 = sin(2*pi*t)*exp(-t) s4 = sin(2*pi*t)*cos(4*pi*t) t = arange(0.0, 2.0, 0.01) plot(t, s1, t, s2+1, t, s3+2, t, s4+3, color='k') ylim(-1,4) yticks(arange(4), ['S1', 'S2', 'S3', 'S4']) show() # <markdowncell> # but then it is difficult to do change the y scale in a reasonable way. # For example when you zoom in on y, the signals on top and bottom will go # off the screen. Often what one wants is for the y location of each # signal to remain in place and the gain of the signal to be changed. #
from matplotlib.mlab import linspace, meshgrid import matplotlib.numerix as nx from pylab import figure,show n = 56 x = linspace(-1.5,1.5,n) X,Y = meshgrid(x,x); Qx = nx.cos(Y) - nx.cos(X) Qz = nx.sin(Y) + nx.sin(X) Qx = (Qx + 1.1) Z = nx.sqrt(X**2 + Y**2)/5; Z = (Z - nx.mlab.amin(Z)) / (nx.mlab.amax(Z) - nx.mlab.amin(Z)) fig = figure() ax = fig.add_subplot(111) ax.pcolormesh(Qx,Qz,Z) show()
def Plot_Data(self): t = numpy.arange(0.0, 5.0, 0.01) s = numpy.sin(2.0 * numpy.pi * t) c = numpy.cos(0.4 * numpy.pi * t) self.axes.plot(t, s) self.axes.plot(t, c)
def draw_networkx_edges(G, pos, edgelist=None, width=1.0, edge_color='k', style='solid', alpha=1.0, edge_cmap=None, edge_vmin=None, edge_vmax=None, ax=None, arrows=True, **kwds): """Draw the edges of the graph G This draws only the edges of the graph G. pos is a dictionary keyed by vertex with a two-tuple of x-y positions as the value. See networkx_v099.layout for functions that compute node positions. edgelist is an optional list of the edges in G to be drawn. If provided, only the edges in edgelist will be drawn. edgecolor can be a list of matplotlib color letters such as 'k' or 'b' that lists the color of each edge; the list must be ordered in the same way as the edge list. Alternatively, this list can contain numbers and those number are mapped to a color scale using the color map edge_cmap. For directed graphs, "arrows" (actually just thicker stubs) are drawn at the head end. Arrows can be turned off with keyword arrows=False. See draw_networkx_v099 for the list of other optional parameters. """ if ax is None: ax=matplotlib.pylab.gca() if edgelist is None: edgelist=G.edges() if not edgelist or len(edgelist)==0: # no edges! return None # set edge positions edge_pos=asarray([(pos[e[0]],pos[e[1]]) for e in edgelist]) if not cb.iterable(width): lw = (width,) else: lw = width if not cb.is_string_like(edge_color) \ and cb.iterable(edge_color) \ and len(edge_color)==len(edge_pos): if matplotlib.numerix.alltrue([cb.is_string_like(c) for c in edge_color]): # (should check ALL elements) # list of color letters such as ['k','r','k',...] edge_colors = tuple([colorConverter.to_rgba(c,alpha) for c in edge_color]) elif matplotlib.numerix.alltrue([not cb.is_string_like(c) for c in edge_color]): # numbers (which are going to be mapped with a colormap) edge_colors = None else: raise ValueError('edge_color must consist of either color names or numbers') else: if len(edge_color)==1: edge_colors = ( colorConverter.to_rgba(edge_color, alpha), ) else: raise ValueError('edge_color must be a single color or list of exactly m colors where m is the number or edges') edge_collection = LineCollection(edge_pos, colors = edge_colors, linewidths = lw, antialiaseds = (1,), linestyle = style, transOffset = ax.transData, ) edge_collection.set_alpha(alpha) # need 0.87.7 or greater for edge colormaps mpl_version=matplotlib.__version__ if mpl_version.endswith('svn'): mpl_version=matplotlib.__version__[0:-3] if mpl_version.endswith('pre'): mpl_version=matplotlib.__version__[0:-3] if map(int,mpl_version.split('.'))>=[0,87,7]: if edge_colors is None: if edge_cmap is not None: assert(isinstance(edge_cmap, Colormap)) edge_collection.set_array(asarray(edge_color)) edge_collection.set_cmap(edge_cmap) if edge_vmin is not None or edge_vmax is not None: edge_collection.set_clim(edge_vmin, edge_vmax) else: edge_collection.autoscale() matplotlib.pylab.sci(edge_collection) # else: # sys.stderr.write(\ # """matplotlib version >= 0.87.7 required for colormapped edges. # (version %s detected)."""%matplotlib.__version__) # raise UserWarning(\ # """matplotlib version >= 0.87.7 required for colormapped edges. # (version %s detected)."""%matplotlib.__version__) arrow_collection=None if G.directed and arrows: # a directed graph hack # draw thick line segments at head end of edge # waiting for someone else to implement arrows that will work arrow_colors = ( colorConverter.to_rgba('k', alpha), ) a_pos=[] p=1.0-0.25 # make head segment 25 percent of edge length for src,dst in edge_pos: x1,y1=src x2,y2=dst dx=x2-x1 # x offset dy=y2-y1 # y offset d=sqrt(float(dx**2+dy**2)) # length of edge if d==0: # source and target at same position continue if dx==0: # vertical edge xa=x2 ya=dy*p+y1 if dy==0: # horizontal edge ya=y2 xa=dx*p+x1 else: theta=arctan2(dy,dx) xa=p*d*cos(theta)+x1 ya=p*d*sin(theta)+y1 a_pos.append(((xa,ya),(x2,y2))) arrow_collection = LineCollection(a_pos, colors = arrow_colors, linewidths = [4*ww for ww in lw], antialiaseds = (1,), transOffset = ax.transData, ) # update view minx = amin(ravel(edge_pos[:,:,0])) maxx = amax(ravel(edge_pos[:,:,0])) miny = amin(ravel(edge_pos[:,:,1])) maxy = amax(ravel(edge_pos[:,:,1])) w = maxx-minx h = maxy-miny padx, pady = 0.05*w, 0.05*h corners = (minx-padx, miny-pady), (maxx+padx, maxy+pady) ax.update_datalim( corners) ax.autoscale_view() edge_collection.set_zorder(1) # edges go behind nodes ax.add_collection(edge_collection) if arrow_collection: arrow_collection.set_zorder(1) # edges go behind nodes ax.add_collection(arrow_collection) return edge_collection
def draw2(): import pylab as P from matplotlib import collections, axes, transforms from matplotlib.colors import colorConverter import matplotlib.numerix as N nverts = 50 npts = 100 # Make some spirals r = N.array(range(nverts)) theta = N.array(range(nverts)) * (2*N.pi)/(nverts-1) xx = r * N.sin(theta) yy = r * N.cos(theta) spiral = zip(xx,yy) # Make some offsets xo = P.randn(npts) yo = P.randn(npts) xyo = zip(xo, yo) # Make a list of colors cycling through the rgbcmyk series. colors = [colorConverter.to_rgba(c) for c in ('r','g','b','c','y','m','k')] fig = P.figure() fig.canvas.mpl_connect('pick_event', on_canvas_pick) a = fig.add_subplot(2,1,1) col = collections.LineCollection([spiral], offsets=xyo, transOffset=a.transData, picker=True) # Note: the first argument to the collection initializer # must be a list of sequences of x,y tuples; we have only # one sequence, but we still have to put it in a list. a.add_collection(col, autolim=True) # autolim=True enables autoscaling. For collections with # offsets like this, it is neither efficient nor accurate, # but it is good enough to generate a plot that you can use # as a starting point. If you know beforehand the range of # x and y that you want to show, it is better to set them # explicitly, leave out the autolim kwarg (or set it to False), # and omit the 'a.autoscale_view()' call below. # Make a transform for the line segments such that their size is # given in points: trans = transforms.scale_transform(fig.dpi/transforms.Value(72.), fig.dpi/transforms.Value(72.)) col.set_transform(trans) # the points to pixels transform col.set_color(colors) a.autoscale_view() # See comment above, after a.add_collection. a.set_title('LineCollection using offsets') # The same data as above, but fill the curves. a = fig.add_subplot(2,1,2) col = collections.PolyCollection([spiral], offsets=xyo, transOffset=a.transData) col._picker =True a.add_collection(col, autolim=True) trans = transforms.scale_transform(fig.dpi/transforms.Value(72.), fig.dpi/transforms.Value(72.)) col.set_transform(trans) # the points to pixels transform col.set_color(colors) a.autoscale_view() a.set_title('PolyCollection using offsets') P.show()
def onTimer(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) self.canvas.draw()
# =================== # # Often one wants to plot many signals over one another. There are a few # ways to do this. The naive implementation is just to add a constant # offset to each signal: # # <codecell> from pylab import plot, show, ylim, yticks from matplotlib.numerix import sin, cos, exp, pi, arange t = arange(0.0, 2.0, 0.01) s1 = sin(2 * pi * t) s2 = exp(-t) s3 = sin(2 * pi * t) * exp(-t) s4 = sin(2 * pi * t) * cos(4 * pi * t) t = arange(0.0, 2.0, 0.01) plot(t, s1, t, s2 + 1, t, s3 + 2, t, s4 + 3, color='k') ylim(-1, 4) yticks(arange(4), ['S1', 'S2', 'S3', 'S4']) show() # <markdowncell> # but then it is difficult to do change the y scale in a reasonable way. # For example when you zoom in on y, the signals on top and bottom will go # off the screen. Often what one wants is for the y location of each # signal to remain in place and the gain of the signal to be changed. #
from openeye.oechem import * import stats from matplotlib.figure import Figure from matplotlib.patches import Polygon from matplotlib.backends.backend_agg import FigureCanvasAgg import matplotlib.numerix as nx def Ellipse((x,y), (rx, ry), resolution=20, orientation=0, **kwargs): theta = 2*nx.pi/resolution*nx.arange(resolution) + orientation xs = x + rx * nx.cos(theta) ys = y + ry * nx.sin(theta) return Polygon(zip(xs, ys), **kwargs) # Read up to 'limit' records that have XLogP values # Return the lists of: # identifiers, molecular weights, XLogP values def read_data(ifs, limit = None): cids = [] weights = [] xlogps = [] for i, mol in enumerate(ifs.GetOEGraphMols()): # Some of the compounds don't have an XLOGP value # Skip those molecules if not OEHasSDData(mol, "PUBCHEM_CACTVS_XLOGP"): continue cid = OEGetSDData(mol, "PUBCHEM_COMPOUND_CID") weight = OEGetSDData(mol, "PUBCHEM_OPENEYE_MW") xlogp = OEGetSDData(mol, "PUBCHEM_CACTVS_XLOGP") if (cid == "" or weight == "" or xlogp == ""): raise AssertionError( (cid, weight, xlogp) )
def Plot_Data(self): t = numpy.arange(0.0,5.0,0.01) s = numpy.sin(2.0*numpy.pi*t) c = numpy.cos(0.4*numpy.pi*t) self.axes.plot(t,s) self.axes.plot(t,c)
backends, and requires that you have tex and the other dependencies described at http://matplotlib.sf.net/matplotlib.texmanager.html properly installed on your system. The first time you run a script you will see a lot of output from tex and associated tools. The next time, the run may be silent, as a lot of the information is cached in ~/.tex.cache """ from matplotlib import rc from matplotlib.numerix import arange, cos, pi from pylab import figure, axes, plot, xlabel, ylabel, title, \ grid, savefig, show rc('text', usetex=True) figure(1) ax = axes([0.1, 0.1, 0.8, 0.7]) t = arange(0.0, 1.0+0.01, 0.01) s = cos(2*2*pi*t)+2 plot(t, s) xlabel(r'\textbf{time (s)}') ylabel(r'\textit{voltage (mV)}',fontsize=16) title(r"\TeX\ is Number $\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$!", fontsize=16, color='r') grid(True) savefig('tex_demo') show()
lowest = fig.add_axes([0, 0, 1, 1], label='lowest') lowest.axesPatch.set_facecolor('green') pylab.setp(lowest, 'xticks', []) pylab.setp(lowest, 'yticks', []) # Now add some axes with real plots... a = fig.add_axes([0, 0, 1, 1], label='a') labelax(a, 'a') a.plot([1, 2, 3], [4, 5, 6], 'r-') b = fig.add_axes([0, 0, 1, 1], label='b') labelax(b, 'b') theta = nx.arange(0, 2 * nx.pi, 0.01) x = nx.cos(theta) y = nx.sin(theta) b.plot(x, y, 'b-') b2 = fig.add_axes([0, 0, 1, 1], label='b2') labelax(b2, 'b2') more_plots = 1 if more_plots: c = fig.add_axes([0, 0, 1, 1], label='c') labelax(c, 'c') d = fig.add_axes([0, 0, 1, 1], label='d') labelax(d, 'd') if 1: