本文整理汇总了Python中matplotlib.pyplot.fignum_exists函数的典型用法代码示例。如果您正苦于以下问题:Python fignum_exists函数的具体用法?Python fignum_exists怎么用?Python fignum_exists使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fignum_exists函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_nominal
def test_nominal(self):
fig1 = plt.figure()
fig2 = plt.figure()
self.assertTrue(plt.fignum_exists(fig1.number))
self.assertTrue(plt.fignum_exists(fig2.number))
dcs.close_all()
self.assertFalse(plt.fignum_exists(fig1.number))
self.assertFalse(plt.fignum_exists(fig2.number))
示例2: _Plot_3D_fired
def _Plot_3D_fired(self):
try:
plt.fignum_exists()
xmin, xmax = plt.xlim()
ymin, ymax = plt.ylim()
index_wavelength_left=(np.abs(Data.wavelength-xmin)).argmin()
index_wavelength_right=(np.abs(Data.wavelength-xmax)).argmin()
index_time_left=(np.abs(Data.time-ymin)).argmin()
index_time_right=(np.abs(Data.time-ymax)).argmin()
except:
index_wavelength_left=0
index_wavelength_right=Data.wavelength[-1]
index_time_left=0
index_time_right=Data.wavelength[-1]
Data.Three_d = Data.TrA_Data[index_time_left:index_time_right,index_wavelength_left:index_wavelength_right]
Data.Three_d_wavelength = Data.wavelength[index_wavelength_left:index_wavelength_right]
Data.Three_d_time = Data.time[index_time_left:index_time_right]
self.scene.mlab.clf()
x = np.linspace(Data.Three_d_wavelength[0],Data.Three_d_wavelength[-1],len(Data.Three_d_wavelength))
y = np.linspace(Data.Three_d_time[0], Data.Three_d_time[-1],len(Data.Three_d_wavelength))
[xi,yi] = np.meshgrid(x,y)
for i in range(len(Data.Three_d_wavelength)):
repeating_wavelength = np.array(np.ones((len(Data.Three_d_time)))*Data.Three_d_wavelength[i])
vectors = np.array([Data.Three_d_time,repeating_wavelength,Data.Three_d[:,i]])
if i==0:
Data.TrA_Data_gridded = vectors
else:
Data.TrA_Data_gridded = np.hstack((Data.TrA_Data_gridded, vectors))
zi = interpolate.griddata((Data.TrA_Data_gridded[1,:],Data.TrA_Data_gridded[0,:]),Data.TrA_Data_gridded[2,:],(xi,yi), method='linear', fill_value=0)
#Sends 3D plot to mayavi in gui
#uncomment for plotting actual data matrix
#self.scene.mlab.surf(Data.time,Data.wavelength,Data.TrA_Data,warp_scale=-self.z_height*100)
#gridded plot which gives correct view
self.plot = self.scene.mlab.surf(yi,xi,zi, warp_scale=-self.z_height*100)
self.scene.mlab.colorbar(orientation="vertical")
self.scene.mlab.axes(nb_labels=5,)
self.scene.mlab.ylabel("wavelength (nm)")
self.scene.mlab.xlabel("time (ps)")
示例3: plot_process
def plot_process(queue, name, labels=None):
"""Grabs data from the queue and plots it in a named figure
"""
# Set up the figure and display it
fig = setup_figure(name)
plt.show(block=False)
if labels is not None:
plt.xlabel(labels[0])
plt.ylabel(labels[1])
while True:
# Get all the data currently on the queue
data = []
while not queue.empty():
data.append(queue.get())
# If there is no data, no need to plot, instead wait for a
# while
if len(data) == 0:
plt.pause(0.015)
continue
# Check if poison pill (None) arrived or the figure was closed
if None in data or not plt.fignum_exists(fig.number):
# If yes, leave the process
break
else:
# Plot the data, then wait 15ms for the plot to update
for datum in data:
plt.plot(*datum)
plt.pause(0.015)
示例4: savefig
def savefig(filename, **kwargs):
"""
Save a figure plotted by Matplotlib.
Note : This function is supposed to be used after the ``plot``
function. Otherwise it will save a blank image with no plot.
Parameters
----------
filename : str
The name of the image file. Extension must be specified in the
file name. For example filename with `.png` extension will give a
rasterized image while `.pdf` extension will give a vectorized
output.
kwargs : keyword arguments
Keyword arguments to be passed to ``savefig`` function of
``matplotlib.pyplot``. For example use `bbox_inches='tight'` to
remove the undesirable whitepace around the image.
"""
try:
import matplotlib.pyplot as plt
except ImportError:
raise ImportError("Matplotlib required for savefig()")
if not plt.fignum_exists(1):
utils.simon("use ``plot`` function to plot the image first and "
"then use ``savefig`` to save the figure.")
plt.savefig(filename, **kwargs)
示例5: make_new_fig
def make_new_fig(fnum=None, close_old=True, return_fig=False,
use_max_fnum=False, **kwargs):
"""
Make a new figure, clearing the old one.
Returns the figure after the one you've created.
"""
if fnum is None:
fignums = get_fignums()
max_fnum = max(fignums) if len(fignums) > 0 else 0
if use_max_fnum:
fnum = max_fnum+1
else:
for fnum in range(0, max_fnum+2):
if fnum not in fignums:
break
if fignum_exists(fnum) and close_old:
close(fnum) # Close the figure if it already exists.
fig = figure(fnum, **kwargs)
clf()
if return_fig:
return [fig, fnum+1]
else:
return fnum+1
开发者ID:pganssle-research,项目名称:alkali-vapor-cell-magnetometry-dissertation,代码行数:29,代码来源:figure_settings.py
示例6: gplot
def gplot(xval, yval, sym=None, xr=None, yr=None, title=None, xlabel=None, \
ylabel=None, tsize=None, xsize=None, ysize=None, color=None, \
fnum=None, fname=None):
# -------- defaults
if sym==None : sym='k-'
if xr==None : xr = min(xval), max(xval)
if yr==None : yr = min(yval), max(yval)
if title==None : title=''
if xlabel==None : xlabel=''
if ylabel==None : ylabel=''
if fnum==None : fnum=0
# -------- make the figure
if plt.fignum_exists(fnum): plt.close(fnum)
plt.figure(fnum)
plt.plot(xval,yval,sym)
plt.xlim(xr)
plt.ylim(yr)
plt.title(title, fontsize=tsize)
plt.xlabel(xlabel, fontsize=xsize)
plt.ylabel(ylabel, fontsize=ysize)
# -------- write to output if desired
if fname!=None:
if not isinstance(fname,list): fname = [fname]
for ifile in fname:
print("GPLOT: Writing output to " + ifile)
plt.savefig(ifile)
else:
plt.show()
示例7: mpl_annotate_interactive
def mpl_annotate_interactive(text, ax=None, arrowprops={"facecolor":'black', "shrink":0.05}):
ax = ax or pyplot.gca()
fig = ax.figure
coordinates = [
None, # xy
None # xytext
]
pause = [True,]
def get_xy(event):
if coordinates[0] is None:
coordinates[0] = (event.x, event.y)
print("xy : {}".format(coordinates[0]))
else:
coordinates[1] = (event.x, event.y)
print("xytext : {}".format(coordinates[1]))
pause[0] = False
cid = fig.canvas.mpl_connect('button_press_event', get_xy)
while pause[0] and pyplot.fignum_exists(fig.number):
fig.canvas.get_tk_widget().update()
fig.canvas.mpl_disconnect(cid)
ax.annotate(
text,
xycoords='figure pixels',
xy=coordinates[0],
xytext=coordinates[1],
arrowprops=arrowprops,
)
示例8: closeFigure
def closeFigure(event): #remove figure from figs
for figure in figs:
if not plt.fignum_exists(figure[0]): #if figure id number doesn't exist, figure doesn't exist
print("removing figure",figure[0])
figs.remove(figure) #remove from figure list
if len(figs) == 0:
raise SystemExit #exit program if all figures have been closed
示例9: mpl_wait_for_key_press
def mpl_wait_for_key_press(fig=None, key="enter", close=False):
# I need to use an object. The pointer to the pause list will be captured by
# closer in key_press_event. When the callback will change the pause
# content, the outer function will see it. With the simple pause = True
# code, the inner function would have changed a local copy of pause.
if fig is None:
fig = pyplot.gcf()
pause = [True, ]
def key_press_event(event):
if event.key == key:
pause[0] = False
cid = fig.canvas.mpl_connect('key_press_event', key_press_event)
while pause[0] and pyplot.fignum_exists(fig.number):
fig.canvas.get_tk_widget().update()
fig.canvas.mpl_disconnect(cid)
if close and pyplot.fignum_exists(fig.number):
pyplot.close(fig.number)
示例10: _redraw
def _redraw(self):
if plt.isinteractive():
fig = self.kwargs["fig"]
if not plt.fignum_exists(fig.number):
fig.show()
fig.canvas.draw()
else:
print("Redraw() is unsupported in non-interactive plotting mode!")
示例11: test_filter_applyFilter
def test_filter_applyFilter(self):
ppmm = self.runBefore()
fake_event = matplotlib.backend_bases.MouseEvent('button_press_event', ppmm.figfilter.canvas, 636, 823)
ppmm.applyFilter(fake_event)
# check the figure has been closed
self.assertFalse(py.fignum_exists(ppmm.figfilter.number))
示例12: _redraw
def _redraw(self):
if plt.isinteractive():
fig = self.kwargs.get('fig',False)
if not fig: return
if not plt.fignum_exists(fig.number):
fig.show()
fig.canvas.draw()
else:
print('Redraw() is unsupported in non-interactive plotting mode!')
示例13: updateTimeUnit
def updateTimeUnit(self,event):
#Verify that the data frame is not empty
if self.df.empty:
messagebox.showinfo('Selection Error', 'Error: Please collect data before selecting time units.')
else:
self.unit = self.timevar.get()
self.unit_conv = self.choices[self.unit]
#Change units on timestamp plots if they exist
self.df['timestamp']=self.df['orig_timestamp'] * self.unit_conv
#Figure two is the EvT plot:
if plt.fignum_exists(2):
self.EvT_plot()
#Figure one is the Time Histogram
if plt.fignum_exists(1):
self.THist_plot()
示例14: display
def display(self, image):
if self.imsh is None or not plt.fignum_exists(self.imsh.figure.number):
self.imsh = plt.imshow(image, interpolation='nearest')
self.imsh.axes.axis('off')
self.imsh.axes.set_position((0, 0, 1, 1))
self.imsh.figure.canvas.draw()
else:
self.imsh.set_data(image)
plt.pause(1e-4)
示例15: animation
def animation():
for i1 in xrange(1, nanim):
# remove previous highlights
icontainer.ax0_hs.remove()
icontainer.ax1_hs.get_sizes()[0] = 20
icontainer.ax1_hs.get_facecolor()[0,0] = 0
icontainer.ax1_hs.get_facecolor()[0,1] = 0.5
icontainer.ax1_hs.get_facecolor()[0,3] = 0.2
icontainer.ax1_hs.get_edgecolor()[0,1] = 0.5
icontainer.ax1_hs.get_edgecolor()[0,3] = 0.2
# remove previous predictive distribution
axes[1].lines.remove(icontainer.prev_line)
# show next sample
icontainer.ax0_hs = axes[0].scatter(mu[i1], sigma[i1], 40, 'r')
icontainer.ax1_hs = axes[1].scatter(
ynew[i1], (0.02 + 0.02*np.random.rand())*np.max(ynewdists), 40, 'r'
)
icontainer.prev_line, = axes[1].plot(
xynew, ynewdists[i1], 'b', linewidth=1.5
)
# update figure
fig.canvas.draw()
# wait animation delay time or until animation is cancelled
stop_anim.wait(anim_delay)
if stop_anim.isSet():
# animation cancelled
break
# skip the rest if the figure does not exist anymore
if not plt.fignum_exists(fig.number):
return
# advance stage
icontainer.stage += 1
# remove highlights
icontainer.ax0_hs.remove()
axes[1].lines.remove(icontainer.prev_line)
icontainer.ax1_hs.get_sizes()[0] = 20
icontainer.ax1_hs.get_facecolor()[0,0] = 0
icontainer.ax1_hs.get_facecolor()[0,1] = 0.5
icontainer.ax1_hs.get_facecolor()[0,3] = 0.2
icontainer.ax1_hs.get_edgecolor()[0,1] = 0.5
icontainer.ax1_hs.get_edgecolor()[0,3] = 0.2
# modify helper text
htext.set_text('press any key to continue')
# plot the rest of the samples
i1 += 1
icontainer.ax1_hs = axes[1].scatter(
ynew[i1:], (0.02 + 0.015*np.random.rand(nsamp-i1))*np.max(ynewdists), 10,
color=[0,0.5,0], alpha=0.2
)
# update legend
axes[1].legend(
(icontainer.ax1_hs,),
('samples from the predictive distribution',),
loc='upper center'
)
fig.canvas.draw()