本文整理汇总了Python中pylab.ion方法的典型用法代码示例。如果您正苦于以下问题:Python pylab.ion方法的具体用法?Python pylab.ion怎么用?Python pylab.ion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pylab
的用法示例。
在下文中一共展示了pylab.ion方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import ion [as 别名]
def __init__(self, add_inputs, title='', **kwargs):
super(OffshorePlot, self).__init__(**kwargs)
self.fig = plt.figure(num=None, facecolor='w', edgecolor='k') #figsize=(13, 8), dpi=1000
self.shape_plot = self.fig.add_subplot(121)
self.objf_plot = self.fig.add_subplot(122)
self.targname = add_inputs
self.title = title
# Adding automatically the inputs
for i in add_inputs:
self.add(i, Float(0.0, iotype='in'))
#sns.set(style="darkgrid")
#self.pal = sns.dark_palette("skyblue", as_cmap=True)
plt.rc('lines', linewidth=1)
plt.ion()
self.force_execute = True
if not pa('fig').exists():
pa('fig').mkdir()
示例2: execute
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import ion [as 别名]
def execute(self):
plt.ion()
if self.inc==0:
try:
pa(self.result_file+'.results').remove()
except:
pass
self.iterations = [self.inc]
self.targvalue = [[getattr(self, i) for i in self.targname]]
self.pre_plot()
else:
self.iterations.append(self.inc)
self.targvalue.append([getattr(self, i) for i in self.targname])
#print self.iterations,self.targvalue
#if self.inc % (2*self.wt_positions.shape[0]) == 0:
#self.refresh()
#plt.show()
self.save_plot('fig/'+self.png_name+'layout%d.png'%(self.inc))
self.inc += 1
示例3: plot_components
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import ion [as 别名]
def plot_components(a, c, dims, savepath=''):
try:
a = a.reshape(np.append(dims, -1), order='F')
except NotImplementedError:
a = a.toarray().reshape(np.append(dims, -1), order='F')
if savepath:
pl.ioff()
for cmp_id, temp_sig in enumerate(c):
fig = pl.figure()
ax_a = fig.add_subplot(211)
ax_c = fig.add_subplot(212)
ax_a.imshow(a[:, :, cmp_id])
ax_c.plot(temp_sig)
fig.suptitle("component " + str(cmp_id))
if savepath:
fig.savefig(savepath + "component_" + str(cmp_id) + '.svg')
print("saving component " + str(cmp_id))
pl.ion()
示例4: save_plot
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import ion [as 别名]
def save_plot(self, filename):
plt.ion()
targarr = np.array(self.targvalue)
self.posi[0].set_xdata(self.wt_positions[:,0])
self.posi[0].set_ydata(self.wt_positions[:,1])
while len(self.plotel)>0:
self.plotel.pop(0).remove()
self.plotel = self.shape_plot.plot(np.array([self.wt_positions[[i,j],0] for i, j in self.elnet_layout.keys()]).T,
np.array([self.wt_positions[[i,j],1] for i, j in self.elnet_layout.keys()]).T, 'y-', linewidth=1)
for i in range(len(self.posb)):
self.posb[i][0].set_xdata(self.iterations)
self.posb[i][0].set_ydata(targarr[:,i])
self.legend.texts[i].set_text('%s = %8.2f'%(self.targname[i], targarr[-1,i]))
self.objf_plot.set_xlim([0, self.iterations[-1]])
self.objf_plot.set_ylim([0.5, 1.2])
if not self.title == '':
plt.title('%s = %8.2f'%(self.title, getattr(self, self.title)))
plt.draw()
#print self.iterations[-1] , ': ' + ', '.join(['%s=%6.2f'%(self.targname[i], targarr[-1,i]) for i in range(len(self.targname))])
with open(self.result_file+'.results','a') as f:
f.write( '%d:'%(self.inc) + ', '.join(['%s=%6.2f'%(self.targname[i], targarr[-1,i]) for i in range(len(self.targname))]) +
'\n')
#plt.show()
#plt.savefig(filename)
display(plt.gcf())
#plt.show()
clear_output(wait=True)
示例5: complex_databoxes
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import ion [as 别名]
def complex_databoxes(ds, script='d[1]+1j*d[2]', escript=None, **kwargs):
"""
Uses databoxes and specified script to generate data and send to
spinmob.plot.complex_data()
Parameters
----------
ds
List of databoxes
script='d[1]+1j*d[2]'
Complex-valued script for data array.
escript=None
Complex-valued script for error bars
See spinmob.plot.complex.data() for additional optional keyword arguments.
See spinmob.data.databox.execute_script() for more information about scripts.
"""
datas = []
labels = []
if escript is None: errors = None
else: errors = []
for d in ds:
datas.append(d(script))
labels.append(_os.path.split(d.path)[-1])
if not escript is None: errors.append(d(escript))
complex_data(datas, errors, label=labels, **kwargs)
if "draw" in kwargs and not kwargs["draw"]: return
_pylab.ion()
_pylab.draw()
_pylab.show()
return ds
示例6: image_format_figure
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import ion [as 别名]
def image_format_figure(figure=None, draw=True):
"""
This formats the figure in a compact way with (hopefully) enough useful
information for printing large data sets. Used mostly for line and scatter
plots with long, information-filled titles.
Chances are somewhat slim this will be ideal for you but it very well might
and is at least a good starting point.
figure=None specify a figure object. None will use gcf()
"""
_pylab.ioff()
if figure == None: figure = _pylab.gcf()
set_figure_window_geometry(figure, (0,0), (550,470))
axes = figure.axes[0]
# set up the title label
axes.title.set_horizontalalignment('right')
axes.title.set_size(8)
axes.title.set_position([1.27,1.02])
axes.title.set_visible(1)
if draw:
_pylab.ion()
_pylab.draw()
示例7: load
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import ion [as 别名]
def load(self):
self.output_attribute = self.config.get('output_attribute', 'prom')
self.feats = clist(self.config.get('features', ["F0", "Gain","dur"]))
self.prom_weights = clist(self.config.get('prom_weights', [0.4, 0.4, 0.2]))
self.param_dir = self.config.get('param_dir', 'acoustic')
self.frame_len = self.config.get('frame_length', 5)
self.level = self.config.get('level','//token[@token_class=\"word\"]')
self.scale_distance = float(self.config.get('scale_distance',0.5))
self.num_octaves = int(self.config.get('num_octaves', 12))
self.wscale = 10 ## this is set in training
self.variances = {} ## this is set in training
if CWT_DEBUG:
pylab.ion()
self.fzero_feat = ''
for f in self.feats:
if 'f0' in f.lower():
self.fzero_feat = f
assert self.fzero_feat != '', 'ProminenceLabeller needs a feature containing f0!'
self.dynamic_size_wavelet = str2bool(self.config.get('dynamic_size_wavelet', 'no'))
self.use_stress_track = str2bool(self.config.get('use_stress_track', 'no'))
self.stress_xpath = self.config.get('stress_xpath', '//syllable[@stress="stress_1"]')
## for plotting/debugging:-
self.text_attribute = self.config.get('text_attribute', 'text')
示例8: plot_mpc_preview
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import ion [as 别名]
def plot_mpc_preview(self):
import pylab
T = self.mpc_timestep
h = stance.com.z
g = -sim.gravity[2]
trange = [sim.time + k * T for k in range(len(self.x_mpc.X))]
pylab.ion()
pylab.clf()
pylab.subplot(211)
pylab.plot(trange, [v[0] for v in self.x_mpc.X])
pylab.plot(trange, [v[0] - v[2] * h / g for v in self.x_mpc.X])
pylab.subplot(212)
pylab.plot(trange, [v[0] for v in self.y_mpc.X])
pylab.plot(trange, [v[0] - v[2] * h / g for v in self.y_mpc.X])
示例9: qqplotp
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import ion [as 别名]
def qqplotp(pv,fileout = None, alphalevel = 0.05,legend=None,xlim=None,ylim=None,ycoord=10,plotsize="652x526",title=None,dohist=True, numbins=50, figsize=[5,5], markersize=2):
'''
Read in p-values from filein and make a qqplot adn histogram.
If fileout is provided, saves the qqplot only at present.
Searches through p until one is found. '''
import pylab as pl
pl.ion()
fs=8
h1=qqplot(pv, fileout, alphalevel,legend,xlim,ylim,addlambda=True, figsize=figsize, markersize=markersize)
#lambda_gc=estimate_lambda(pv)
#pl.legend(["gc="+ '%1.3f' % lambda_gc],loc=2)
pl.title(title,fontsize=fs)
wm=pl.get_current_fig_manager()
#e.g. "652x526+100+10
xcoord=100
#wm.window.wm_geometry(plotsize + "+" + str(xcoord) + "+" + str(ycoord))
if dohist:
h2=pvalhist(pv, numbins=numbins, figsize=figsize)
pl.title(title,fontsize=fs)
#wm=pl.get_current_fig_manager()
width_height=plotsize.split("x")
buffer=10
xcoord=int(xcoord + float(width_height[0])+buffer)
#wm.window.wm_geometry(plotsize + "+" + str(xcoord) + "+" + str(ycoord))
else: h2=None
return h1,h2
示例10: __init__
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import ion [as 别名]
def __init__(self, ca, cmap=None, **kwds):
"""CAPlotter() constructor keeps a reference to the CA model, and
optionally a colormap to be used with plots.
Parameters
----------
ca : LandlabCellularAutomaton object
Reference to a CA model
cmap : Matplotlib colormap, optional
Colormap to be used in plotting
"""
import matplotlib
# Set the colormap; default to matplotlib's "jet" colormap
if cmap is None:
self._cmap = matplotlib.cm.jet
else:
self._cmap = cmap
# Keep a reference to the CA model
self.ca = ca
# Initialize the plot and remember the grid type
plt.ion()
plt.figure(1)
if type(ca.grid) is landlab.grid.hex.HexModelGrid:
self.gridtype = "hex"
else:
self.gridtype = "rast"
示例11: __init__
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import ion [as 别名]
def __init__(self, modules, vis):
pylab.style.use('ggplot')
self.node_size_add = 1.5
self.init_node_size = 0.1
self.edge_weight_add = 0.1
self.init_edge_weight = 0.0
self.fixed_path = [[None] * 3] * 3
self.fixed_color = None
self.fixed_weight = 6.4
pylab.ion()
self.graph = nx.Graph()
self.node_ids = {}
node_num = 0
self.vis = vis
if not self.vis:
print("visualizing graph disabled!!")
for layer_num, one_layer in enumerate(modules):
for module_num in range(one_layer):
self.graph.add_node(node_num, Position=(10 * layer_num, 10 * module_num), size = self.init_node_size)
self.node_ids[(layer_num, module_num)] = node_num
node_num += 1
pylab.show()
示例12: peak_smooth
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import ion [as 别名]
def peak_smooth(params, max_iter, win,
min_win=2, voicing=[], TRACE=False):
"""
Iterative smoothing while preserving peaks, 'true envelope' -style
"""
smoothed = np.array(params)
win_reduce = np.exp(np.linspace(np.log(win), np.log(min_win), max_iter))
# std = np.std(params)
if TRACE:
pylab.ion()
pylab.plot(params, 'black')
for i in range(0, max_iter):
smoothed = np.maximum(params, smoothed)
# if TRACE:
# if (i > 0) and (i % 2 == 0):
# pass
# pylab.plot(smoothed, 'gray', linewidth=1)
# raw_input()
if len(voicing) > 0:
smoothed = smooth(smoothed, int(win+0.5))
smoothed[voicing > 0] = params[voicing > 0]
else:
smoothed = smooth(smoothed, int(win+0.5), type='rectangle')
win = win_reduce[i]
if TRACE:
pylab.plot(smoothed, 'red', linewidth=2)
pylab.show()
return smoothed
示例13: pre_plot
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import ion [as 别名]
def pre_plot(self):
plt.ion()
#plt.show()
### Plot the water depth
N = 100
self.X, self.Y = plt.meshgrid(plt.linspace(self.depth[:,0].min(), self.depth[:,0].max(), N),
plt.linspace(self.depth[:,1].min(), self.depth[:,1].max(), N))
self.Z = plt.griddata(self.depth[:,0],self.depth[:,1],self.depth[:,2],self.X,self.Y, interp='linear')
Zin = points_in_poly(self.X,self.Y, self.borders)
self.Z.mask = Zin.__neg__()
#Z.mask = False
#Z.data[Zin.__neg__()] = -20.0
display(plt.gcf())
# def refresh(self):
self.shape_plot.clear()
self.shape_plot.contourf(self.X, self.Y, self.Z, 10, vmax=self.depth[:,2].max()) #, cmap=self.pal
self.shape_plot.set_aspect('equal')
self.shape_plot.autoscale(tight=True)
Plot = lambda b, *args, **kwargs: self.shape_plot.plot(b[:,0], b[:,1],*args, **kwargs)
if self.distribution == 'spiral':
spiral = lambda t_, a_, x_: [a_*t_**(1./x_) * np.cos(t_), a_*t_**(1./x_) * np.sin(t_)]
spirals = lambda ts_, a_, x_: np.array([spiral(t_, a_, x_) for t_ in ts_])
for P in self.baseline:
Plot(P + spirals(plt.linspace(0.,10*np.pi,1000), self.spiral_param, 1.), 'g-', linewidth=0.1)
self.shape_plot.plot(self.borders[:,0], self.borders[:,1],'k-')
self.posi = self.shape_plot.plot(self.wt_positions[:,0], self.wt_positions[:,1],'ro')
self.plotel = self.shape_plot.plot(np.array([self.baseline[[i,j],0] for i, j in self.elnet_layout.keys()]).T,
np.array([self.baseline[[i,j],1] for i, j in self.elnet_layout.keys()]).T, 'y--', linewidth=1)
#print self.plotel
self.objf_plot.clear()
targarr = np.array(self.targvalue)
self.posb = []
for i in range(targarr.shape[1]):
self.posb.append(self.objf_plot.plot(self.iterations, self.targvalue[0][i],'.', label=self.targname[i]))
print 'posb', self.posb
self.legend = self.objf_plot.legend(loc=3, bbox_to_anchor=(1.1, 0.0))
plt.title('Foundation = %8.2f'%(self.foundation_length))
plt.draw()
示例14: Plot
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import ion [as 别名]
def Plot(filename=None, data=None, timemarks=None,
events=None, eventfile=None,
ylim=None, columns=(0, 1),
autoscale=True):
"""Plot from ipython.
Args:
filename (string): name of a data file to plot. This will be loaded
into a DataSet object.
data (DataSet): pre-existing dataset to plot. Mutually exclusive
with filename parameter.
timemarks (string): a time spec indicating a span of time to slice.
eventfile (string): name of data file containing event marks.
events (DataSet): A pre-existing event dataset.
ylim (tuple of (min, max): minimum and maximum Y values to plot.
columns (int, or sequence of ints): The column number, or numbers,
starting from zero that will be extracted out (vertical slice).
autoscale (bool): If True, automatically fit graph scale to data.
False means use a fixed scale (2.5 amp max).
"""
if filename is not None:
data = dataset.DataSet(filename=filename)
if eventfile is not None:
events = dataset.DataSet(filename=eventfile)
if data is None:
print "You should supply a filename or a dataset."
return
if timemarks:
data.timeslice(timemarks)
make_plots(data, ylim=ylim, events=events,
columns=columns, autoscale=autoscale, interactive=True)
pylab.gcf().set_size_inches((9,7))
#plotaxes = pylab.gca()
pylab.subplots_adjust(bottom=0.15)
pylab.ion()
pylab.show()
示例15: complex_data
# 需要导入模块: import pylab [as 别名]
# 或者: from pylab import ion [as 别名]
def complex_data(data, edata=None, draw=True, **kwargs):
"""
Plots the imaginary vs real for complex data.
Parameters
----------
data
Array of complex data
edata=None
Array of complex error bars
draw=True
Draw the plot after it's assembled?
See spinmob.plot.xy.data() for additional optional keyword arguments.
"""
_pylab.ioff()
# generate the data the easy way
try:
rdata = _n.real(data)
idata = _n.imag(data)
if edata is None:
erdata = None
eidata = None
else:
erdata = _n.real(edata)
eidata = _n.imag(edata)
# generate the data the hard way.
except:
rdata = []
idata = []
if edata is None:
erdata = None
eidata = None
else:
erdata = []
eidata = []
for n in range(len(data)):
rdata.append(_n.real(data[n]))
idata.append(_n.imag(data[n]))
if not edata is None:
erdata.append(_n.real(edata[n]))
eidata.append(_n.imag(edata[n]))
if 'xlabel' not in kwargs: kwargs['xlabel'] = 'Real'
if 'ylabel' not in kwargs: kwargs['ylabel'] = 'Imaginary'
xy_data(rdata, idata, eidata, erdata, draw=False, **kwargs)
if draw:
_pylab.ion()
_pylab.draw()
_pylab.show()