本文整理汇总了Python中matplotlib.numerix.arange函数的典型用法代码示例。如果您正苦于以下问题:Python arange函数的具体用法?Python arange怎么用?Python arange使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了arange函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gen_colors
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))
示例2: init_plot_data
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')
示例3: init_plot_data
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')
示例4: OnInit
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
示例5: createDBGraph
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)
示例6: __init__
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)
示例7: __init__
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)
示例8: gaussian_example
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
示例9: pplot
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)
示例10: __init__
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)
示例11: 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])
示例12: _create_plot
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')
示例13: _find_axes
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
示例14: __init__
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 )
示例15: test_matplotlib
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")