本文整理汇总了Python中pylab.isinteractive函数的典型用法代码示例。如果您正苦于以下问题:Python isinteractive函数的具体用法?Python isinteractive怎么用?Python isinteractive使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isinteractive函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: hinton
def hinton(W, out_file=None, maxWeight=None):
"""
Draws a Hinton diagram for visualizing a weight matrix.
Temporarily disables matplotlib interactive mode if it is on,
otherwise this takes forever.
"""
reenable = False
if P.isinteractive():
P.ioff()
P.clf()
height, width = W.shape
if not maxWeight:
maxWeight = 2**N.ceil(N.log(N.max(N.abs(W)))/N.log(2))
P.gca().set_position([0, 0, 1, 1])
P.fill(N.array([0,width,width,0]),N.array([0,0,height,height]),'gray')
P.axis('off')
P.axis('equal')
for x in xrange(width):
for y in xrange(height):
_x = x+1
_y = y+1
w = W[y,x]
if w > 0:
_blob(_x - 0.5, height - _y + 0.5, min(1,w/maxWeight),'white')
elif w < 0:
_blob(_x - 0.5, height - _y + 0.5, min(1,-w/maxWeight),'black')
if reenable:
P.ion()
#P.show()
if out_file:
#P.savefig(out_file, format='png', bbox_inches='tight', pad_inches=0)
fig = P.gcf()
fig.subplots_adjust()
fig.savefig(out_file)
示例2: hinton
def hinton(W, max_weight=None, names=(names, worst_names)):
"""
Draws a Hinton diagram for visualizing a weight matrix.
Temporarily disables matplotlib interactive mode if it is on,
otherwise this takes forever.
"""
reenable = False
if P.isinteractive():
P.ioff()
P.clf()
height, width = W.shape
if not max_weight:
max_weight = 2**np.ceil(np.log(np.max(np.abs(W)))/np.log(2))
P.fill(np.array([0, width, width, 0]), np.array([0, 0, height, height]), 'gray')
P.axis('off')
P.axis('equal')
cmap = plt.get_cmap('RdYlGn')
for x in range(width):
if names:
plt.text(-0.5, x, names[0][x], fontsize=7, ha='right', va='bottom')
plt.text(x, height+0.5, names[1][height-x-1], fontsize=7, va='bottom', rotation='vertical', ha='left')
for y in range(height):
_x = x+1
_y = y+1
w = W[y, x]
if w > 0:
_blob(_x - 0.5, height - _y + 0.5, min(1, w/max_weight), color=cmap(w/max_weight))
elif w < 0:
_blob(_x - 0.5, height - _y + 0.5, min(1, -w/max_weight), 'black')
if reenable:
P.ion()
P.show()
示例3: plot
def plot(self):
fig = self._doPlot()
if not pylab.isinteractive():
pylab.show()
else:
pylab.draw()
pylab.close(fig)
示例4: hinton
def hinton(W, maxWeight=None):
"""
Draws a Hinton diagram for visualizing a weight matrix.
Temporarily disables matplotlib interactive mode if it is on,
otherwise this takes forever.
"""
reenable = False
if P.isinteractive():
P.ioff()
P.clf()
height, width = W.shape
if not maxWeight:
maxWeight = 2**N.ceil(N.log(N.max(N.abs(W)))/N.log(2))
P.fill(N.array([0,width,width,0]),N.array([0,0,height,height]),'gray')
P.axis('off')
P.axis('equal')
for x in xrange(width):
for y in xrange(height):
_x = x+1
_y = y+1
w = W[y,x]
if w > 0:
_blob(_x - 0.5, height - _y + 0.5, min(1,w/maxWeight),'white')
elif w < 0:
_blob(_x - 0.5, height - _y + 0.5, min(1,-w/maxWeight),'black')
if reenable:
P.ion()
P.show()
示例5: draw
def draw(self, axes=None, loc=2):
if axes == None:
axes = p.gca()
if self.box != None and self.box in axes.artists:
del axes.artists[ axes.artists.index(self.box) ]
#key_areas = [ mpl.offsetbox.TextArea(k, textprops=self.textprops) for k in self.datadict.keys() ]
#val_areas = [ mpl.offsetbox.TextArea(self.datadict[k], textprops=self.textprops) for k in self.datadict.keys() ]
key_areas = [ mpl.offsetbox.TextArea(k, textprops=self.textprops) for k in list(self.datadict.keys()) ]
val_areas = [ mpl.offsetbox.TextArea(self.datadict[k], textprops=self.textprops) for k in list(self.datadict.keys()) ]
key_vpack = mpl.offsetbox.VPacker(children=key_areas, align="left", pad=0, sep=0)
val_vpack = mpl.offsetbox.VPacker(children=val_areas, align="right", pad=0, sep=0)
hpack = mpl.offsetbox.HPacker(children=[key_vpack, val_vpack], align="top", pad=0,sep=4)
globchildren = []
if self.title != None:
#titlearea = mpl.offsetbox.TextArea(self.title, textprops=self.titleprops)
titlearea = mpl.offsetbox.TextArea(self.title)
globchildren.append(titlearea)
globchildren.append(hpack)
globvpack = mpl.offsetbox.VPacker(children=globchildren, align="center", pad=0, sep=1)
self.box = mpl.offsetbox.AnchoredOffsetbox(loc=loc, child=globvpack)
self.box.patch.set_facecolor(self.facecolor)
self.box.patch.set_edgecolor(self.edgecolor)
self.box.patch.set_alpha(self.alpha)
axes.add_artist( self.box )
if p.isinteractive():
p.gcf().canvas.draw()
示例6: graticule
def graticule(dpar=None,dmer=None,coord=None,local=None,**kwds):
"""Create a graticule, either on an existing mollweide map or not.
Parameters:
- dpar, dmer: interval in degrees between meridians and between parallels
- coord: the coordinate system of the graticule (make rotation if needed,
using coordinate system of the map if it is defined)
- local: True if local graticule (no rotation is performed)
Return:
None
"""
f = pylab.gcf()
wasinteractive = pylab.isinteractive()
pylab.ioff()
try:
if len(f.get_axes()) == 0:
ax=PA.HpxMollweideAxes(f,(0.02,0.05,0.96,0.9),coord=coord)
f.add_axes(ax)
ax.text(0.86,0.05,ax.proj.coordsysstr,fontsize=14,
fontweight='bold',transform=ax.transAxes)
for ax in f.get_axes():
if isinstance(ax,PA.SphericalProjAxes):
ax.graticule(dpar=dpar,dmer=dmer,coord=coord,
local=local,**kwds)
finally:
pylab.draw()
if wasinteractive:
pylab.ion()
示例7: showslice2
def showslice2(thedata,thelabel,minval,maxval,colormap):
theshape=thedata.shape
numslices=theshape[0]
ysize=theshape[1]
xsize=theshape[2]
slicesqrt=int(np.ceil(np.sqrt(numslices)))
theslice=np.zeros((ysize*slicesqrt,xsize*slicesqrt))
for i in range(0,numslices):
ypos=int(i/slicesqrt)*ysize
xpos=int(i%slicesqrt)*xsize
theslice[ypos:ypos+ysize,xpos:xpos+xsize]=thedata[i,:,:]
if P.isinteractive():
P.ioff()
P.axis('off')
P.axis('equal')
P.subplots_adjust(hspace=0.0)
P.axes([0,0,1,1], frameon = False)
if (colormap==0):
thecmap=P.cm.gray
else:
mycmdata1 = {
'red' : ((0., 0., 0.), (0.5, 1.0, 0.0), (1., 1., 1.)),
'green': ((0., 0., 0.), (0.5, 1.0, 1.0), (1., 0., 0.)),
'blue' : ((0., 0., 0.), (0.5, 1.0, 0.0), (1., 0., 0.))
}
thecmap = P.matplotlib.colors.LinearSegmentedColormap('mycm', mycmdata1)
#thecmap=P.cm.spectral
theimptr = P.imshow(theslice, vmin=minval, vmax=maxval, interpolation='nearest', label=thelabel, aspect='equal', cmap=thecmap)
#P.colorbar()
return()
示例8: showlines
def showlines(vs, size=(4.1,2), **kwargs):
# {{{
'''
Plot line plots of a list of 1D variables on the same plot.
Parameters
----------
v : list of :class:`Var`
The variables to plot. Should all have 1 non-degenerate axis.
'''
Z = [v.squeeze() for v in vs]
for z in Z:
assert z.naxes == 1, 'Variable %s has %d non-generate axes; must have 1.' % (z.name, z.naxes)
fig = kwargs.pop('fig', None)
ax = wr.AxesWrapper(size=size)
ydat = []
for v in vs:
vplot(v, axes=ax, label=v.name, )
ydat.append(ax.find_plot(wr.Plot).plot_args[1])
ylim = (np.min([np.min(y) for y in ydat]), np.max([np.max(y) for y in ydat]))
kwargs.update(dict(ylim=ylim))
ax.legend(loc='best', frameon=False)
ax.setp(**kwargs)
import pylab as pyl
if pyl.isinteractive(): ax.render(fig)
return ax
示例9: saveHintonDiagram
def saveHintonDiagram(W, directory):
maxWeight = None
#print "Weight: ", W
"""
Draws a Hinton diagram for visualizing a weight matrix.
Temporarily disables matplotlib interactive mode if it is on,
otherwise this takes forever.
"""
reenable = False
if pylab.isinteractive():
pylab.ioff()
pylab.clf()
height, width = W.shape
if not maxWeight:
maxWeight = 2**numpy.ceil(numpy.log(numpy.max(numpy.abs(W)))/numpy.log(2))
pylab.fill(numpy.array([0,width,width,0]),numpy.array([0,0,height,height]),'gray')
pylab.axis('off')
pylab.axis('equal')
for x in xrange(width):
for y in xrange(height):
_x = x+1
_y = y+1
w = W[y,x]
if w > 0:
_blob(_x - 0.5, height - _y + 0.5, min(1,w/maxWeight),'white')
elif w < 0:
_blob(_x - 0.5, height - _y + 0.5, min(1,-w/maxWeight),'black')
if reenable:
pylab.ion()
#pylab.show()
pylab.savefig(directory)
示例10: hinton
def hinton(W, maxWeight=None):
"""
Source: http://wiki.scipy.org/Cookbook/Matplotlib/HintonDiagrams
Draws a Hinton diagram for visualizing a weight matrix.
Temporarily disables matplotlib interactive mode if it is on,
otherwise this takes forever.
"""
reenable = False
if pl.isinteractive():
pl.ioff()
pl.clf()
height, width = W.shape
if not maxWeight:
maxWeight = 2**np.ceil(np.log(np.max(np.abs(W)))/np.log(2))
pl.fill(np.array([0,width,width,0]),np.array([0,0,height,height]),'gray')
pl.axis('off')
pl.axis('equal')
for x in xrange(width):
for y in xrange(height):
_x = x+1
_y = y+1
w = W[y,x]
if w > 0:
_blob(_x - 0.5, height - _y + 0.5, min(1,w/maxWeight),'white')
elif w < 0:
_blob(_x - 0.5, height - _y + 0.5, min(1,-w/maxWeight),'black')
if reenable:
pl.ion()
pl.show()
示例11: hinton
def hinton(W,filename="hinton.pdf", maxWeight=None):
"""
Draws a Hinton diagram for visualizing a weight matrix.
Temporarily disables matplotlib interactive mode if it is on,
otherwise this takes forever.
"""
reenable = False
if P.isinteractive():
P.ioff()
P.clf()
ax=P.subplot(111)
height, width = W.shape
if not maxWeight:
maxWeight = 2**np.ceil(np.log(np.max(np.abs(W)))/np.log(2))
P.fill(np.array([0,width,width,0]),np.array([0,0,height,height]),'gray')
P.axis('off')
#P.axis('equal')
ax.set_yticklabels(['25','20','15','10','5','0'])
for x in xrange(width):
for y in xrange(height):
_x = x+1
_y = y+1
w = W[y,x]
if w > 0:
_blob(_x - 0.5, height - _y + 0.5, min(1,w/maxWeight),'white')
elif w < 0:
_blob(_x - 0.5, height - _y + 0.5, min(1,-w/maxWeight),'black')
if reenable:
P.ion()
P.title(filename)
P.savefig(filename)
示例12: __call__
def __call__(self,output_fn,init_time=0,final_time=None,**params):
p=ParamOverrides(self,params)
if final_time is None:
final_time=topo.sim.time()
attrs = p.attrib_names if len(p.attrib_names)>0 else output_fn.attrib_names
for a in attrs:
pylab.figure(figsize=(6,4))
isint=pylab.isinteractive()
pylab.ioff()
pylab.grid(True)
ylabel=p.ylabel
pylab.ylabel(a+" "+ylabel)
pylab.xlabel('Iteration Number')
coords = p.units if len(p.units)>0 else output_fn.units
for coord in coords:
y_data=[y for (x,y) in output_fn.values[a][coord]]
x_data=[x for (x,y) in output_fn.values[a][coord]]
if p.raw==True:
plot_data=zip(x_data,y_data)
pylab.save(normalize_path(p.filename+a+'(%.2f, %.2f)' %(coord[0], coord[1])),plot_data,fmt='%.6f', delimiter=',')
pylab.plot(x_data,y_data, label='Unit (%.2f, %.2f)' %(coord[0], coord[1]))
(ymin,ymax)=p.ybounds
pylab.axis(xmin=init_time,xmax=final_time,ymin=ymin,ymax=ymax)
if isint: pylab.ion()
pylab.legend(loc=0)
p.title=topo.sim.name+': '+a
p.filename_suffix=a
self._generate_figure(p)
示例13: read_text_pyfusion
def read_text_pyfusion(files, target='^Shot .*', ph_dtype=None, plot=pl.isinteractive(), ms=100, hold=0, debug=0, quiet=1, exception = Exception):
""" Accepts a file or a list of files, returns a list of structured arrays
See merge ds_list to merge and convert types (float -> pyfusion.prec_med
"""
st = seconds(); last_update=seconds()
file_list = files
if len(np.shape(files)) == 0: file_list = [file_list]
f='f8'
if ph_dtype == None: ph_dtype = [('p12',f),('p23',f),('p34',f),('p45',f),('p56',f)]
#ph_dtype = [('p12',f)]
ds_list =[]
comment_list =[]
count = 0
for (i,filename) in enumerate(file_list):
if seconds() - last_update > 30:
last_update = seconds()
print('reading {n}/{t}: {f}'
.format(f=filename, n=i, t=len(file_list)))
try:
if pl.is_string_like(target):
skip = 1+find_data(filename, target,debug=debug)
else:
skip = target
if quiet == 0:
print('{t:.1f} sec, loading data from line {s} of {f}'
.format(t = seconds()-st, s=skip, f=filename))
# this little bit to determine layout of data
# very inefficient to read twice, but in a hurry!
txt = np.loadtxt(fname=filename, skiprows=skip-1, dtype=str,
delimiter='FOOBARWOOBAR')
header_toks = txt[0].split()
# is the first character of the 2nd last a digit?
if header_toks[-2][0] in '0123456789':
if pyfusion.VERBOSE > 0:
print('found new header including number of phases')
n_phases = int(header_toks[-2])
ph_dtype = [('p{n}{np1}'.format(n=n,np1=n+1), f) for n in range(n_phases)]
if 'frlow' in header_toks: # add the two extra fields
fs_dtype= [ ('shot','i8'), ('t_mid','f8'),
('_binary_svs','i8'),
('freq','f8'), ('amp', 'f8'), ('a12','f8'),
('p', 'f8'), ('H','f8'),
('frlow','f8'), ('frhigh', 'f8'),('phases',ph_dtype)]
else:
fs_dtype= [ ('shot','i8'), ('t_mid','f8'),
('_binary_svs','i8'),
('freq','f8'), ('amp', 'f8'), ('a12','f8'),
('p', 'f8'), ('H','f8'), ('phases',ph_dtype)]
ds_list.append(
np.loadtxt(fname=filename, skiprows = skip,
dtype= fs_dtype)
)
count += 1
comment_list.append(filename)
except ValueError, info:
print('Conversion error while reading {f} with loadtxt - {info}'.format(f=filename, info=info))
示例14: showcol
def showcol(vs, size=(4.1,2), **kwargs):
# {{{
'''
Plot variable, showing a contour plot for 2d variables or a line plot for 1d variables.
Parameters
----------
v : list of lists of :class:`Var`
The variables to plot. Should have either 1 or 2 non-degenerate axes.
Notes
-----
This function is intended as the simplest way to display the contents of a variable,
choosing appropriate parameter values as automatically as possible.
'''
Z = [v.squeeze() for v in vs]
assert Z[0].naxes in [1, 2], 'Variables %s has %d non-generate axes; must have 1 or 2.' % (Z.name, Z.naxes)
for z in Z[1:]:
assert Z[0].naxes == z.naxes, 'All variables must have the same number of non-generate dimensions'
#assert all([a == b for a, b in zip(Z[0].axes, z.axes)])
fig = kwargs.pop('fig', None)
if Z[0].naxes == 1:
axs = []
ydat = []
for v in vs:
lblx = (v is vs[-1])
ax = vplot(v, lblx = lblx, **kwargs)
ax.size = size
axs.append([ax])
ydat.append(ax.find_plot(wr.Plot).plot_args[1])
Ax = wr.grid(axs)
ylim = (np.min([np.min(y) for y in ydat]), np.max([np.max(y) for y in ydat]))
Ax.setp(ylim = ylim, children=True)
elif Z[0].naxes == 2:
axs = []
for v in vs:
lblx = (v is vs[-1])
ax = vcontour(v, lblx = lblx, **kwargs)
ax.size = size
axs.append([ax])
Ax = wr.grid(axs)
cbar = kwargs.pop('colorbar', dict(orientation='vertical'))
cf = Ax.axes[0].find_plot(wr.Contourf)
if cbar and cf is not None:
Ax = wr.colorbar(Ax, cf, **cbar)
import pylab as pyl
if pyl.isinteractive(): Ax.render(fig)
return Ax
示例15: showslice
def showslice(theslice):
if P.isinteractive():
P.ioff()
P.axis('off')
P.axis('equal')
P.axis('tight')
P.imshow(theslice, interpolation='nearest', aspect='equal', cmap=P.cm.gray)
P.colorbar()
return()