本文整理汇总了Python中matplotlib.pyplot.interactive函数的典型用法代码示例。如果您正苦于以下问题:Python interactive函数的具体用法?Python interactive怎么用?Python interactive使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了interactive函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plotResults
def plotResults(results):
plt.interactive(True)
plt.subplot(131)
plt.plot(results.xpos, color='b',label='X Position')
plt.plot(results.ypos, linestyle='--', color='r', label='Y Position')
plt.plot(results.zpos, linestyle='-', color='y', label='Z Position')
plt.xlabel('Time')
plt.ylabel('Distance')
plt.title('Distance Traveled')
plt.legend()
plt.show()
ts = range(0,len(results),6)
plt.subplot(131)
pt = plt.plot(0,results.zpos[0], 'ro', markersize=4)
for t in ts:
plt.subplot(131)
pt[0].set_ydata(results.zpos[t])
pt[0].set_xdata(t)
ax1 = plt.subplot(132)
ax1.clear()
plt.bar(range(6), results[t].lowerleglinearmag)
ax2 = plt.subplot(133)
ax2.clear()
plt.bar(range(6), results[t].upperleglinearmag)
plt.draw()
time.sleep(0.01)
示例2: print_all
def print_all(fnames, freq, spec1, spec2, rms1, rms2, bw=(0,1600)):
'''
Print all power spectra to PDF files
'''
# Construct path for saving figures and notify
base_dir = os.path.join(os.getcwd(), 'figures')
if not os.path.exists(base_dir):
os.mkdir(base_dir)
print('\nsaving figures to {s} ... '.format(s=base_dir), flush=True)
# Plot and save figures for each channel's spectrum
on = plt.isinteractive()
plt.ioff()
for chan in range(spec1.shape[-1]):
fig = comp_spectra(freq, spec1, spec2, channel=chan, bw=bw)
plt.title('Channel {0:d}'.format(chan))
plt.xlabel('Frequency (Hz)')
plt.ylabel('Power')
plt.legend(('Before', 'After'))
print('figure {:02d}'.format(chan), flush=True)
plt.savefig(os.path.join(base_dir, 'channel{0:02d}.png'.format(chan)), format='png')
plt.close(fig)
# Plot and save figure showing RMS ratio
fig = plt.figure()
plt.plot(rms2 / rms1, 'o')
plt.title('RMS ratio (after / before)')
plt.xlabel('Channel')
plt.savefig(os.path.join(base_dir, 'rms_ratio.png'), format='png')
plt.close(fig)
# Notify
plt.interactive(on)
print('done.')
示例3: lvmTwoDPlot
def lvmTwoDPlot(X, lbl=None, symbol=None):
"""Helper function for plotting the labels in 2-D.
Description:
lvmTwoDPlot(X, lbl, symbol) helper function for plotting an
embedding in 2-D with symbols.
Arguments:
X - the data to plot.
lbl - the labels of the data point.
symbol - the symbols to use for the different labels.
See also
lvmScatterPlot, lvmVisualise
Copyright (c) 2004, 2005, 2006, 2008, 2009 Neil D. Lawrence
"""
if lbl=='connect':
connect = True
lbl = None
else:
connect = False
if symbol is None:
if lbl is None:
symbol = ndlutil.getSymbols(1)
else:
symbol = ndlutil.getSymbols(lbl.shape[1])
axisHand = pp.gca()
returnVal = []
holdState = axisHand.ishold()
intState = pp.isinteractive()
pp.interactive(False)
for i in range(X.shape[0]):
if i == 1:
axisHand.hold(True)
if lbl is not None:
labelNo = np.flatnonzero(lbl[i])
else:
labelNo = 0
try:
returnVal.append(axisHand.plot([X[i, 0]], [X[i, 1]], symbol[labelNo], markersize=10, linewidth=2))
if connect:
if i>0:
axisHand.plot([X[i-1, 0], X[i, 0]], [X[i-1, 1], X[i, 1]], 'r')
except(NotImplementedError):
raise NotImplementedError('Only '+ str(len(symbol)) + ' labels supported (it''s easy to add more!)')
axisHand.hold(holdState)
if intState:
pp.show()
pp.interactive(intState)
return returnVal
示例4: plot_gamma_1_storage
def plot_gamma_1_storage():
plt.figure()
ts=get_mismatch(1.0)
dummy,storage_capacity,storage_level=get_policy_2_storage(ts,return_storage_filling_time_series=True)
plt.plot(storage_level)
plt.interactive(1)
plt.show()
示例5: plot_path2d
def plot_path2d(data1, data2, data3, data4):
x1=[x for [x, y, z] in data1]
y1=[y for [x, y, z] in data1]
z1=[z for [x, y, z] in data1]
x2=[x for [x, y, z] in data2]
y2=[y for [x, y, z] in data2]
z2=[z for [x, y, z] in data2]
mx1=[x for [x, y, z] in data3]
my1=[y for [x, y, z] in data3]
mz1=[z for [x, y, z] in data3]
mx2=[x for [x, y, z] in data4]
my2=[y for [x, y, z] in data4]
mz2=[z for [x, y, z] in data4]
pltxy=plt.plot(x1,y1, 'ro-',label='xy')
pltuv=plt.plot(x2,y2, 'bs-',label='uv')
mpltxy=plt.plot(mx1,my1, 'go-',label='cut_xy')
mpltuv=plt.plot(mx2,my2, 'ks-',label='cut_uv')
plt.legend()
plt.axis('equal')
plt.axis([min([min(x1),min(x2),min(mx1),min(mx2)]),\
max([max(x1),max(x2),max(mx1),max(mx2)]),\
min([min(y1),min(y2),min(my1),min(my2)]),\
max([max(y1),max(y2),max(my1),max(my2)])])
plt.grid(True)
plt.interactive(True)
plt.show(block=False)
# plt.show()
plt.hold(True)
示例6: cosp_plot_column_2D
def cosp_plot_column_2D(fnc, varname='equivalent_reflectivity_factor', level=0, column = 0, time = 0):
"""
Function that plots one column of lat/lon data.
"""
plt.interactive(True)
fig=plt.figure()
ax = fig.add_subplot(111)
# Read cube
z=iris.load(fnc)
z=z[0]
# Get coords
c = z.coord('column')
t = z.coord('time')
# Select time and column
y=z.extract(iris.Constraint(column=c.points[column]))
y=y.extract(iris.Constraint(time=t.points[time]))
# Select level. Not managed to make constrain with 'atmospheric model level'
y=y[level]
color_map = mpl_cm.get_cmap('Paired')
qplt.pcolormesh(y,cmap=color_map,vmin=-20,vmax=20)
plt.gca().coastlines()
return
示例7: plot_data_dict
def plot_data_dict(data_dict, plots = None, mode = 'static', hang = True, figure = None, size = None, **plot_preference_kwargs):
"""
Make a plot of data in the format defined in data_dict
:param data_dict: dict<str: plottable_data>
:param plots: Optionally, a dict of <key: IPlot> identifying the plot objects to use (keys should
be the same as those in data_dict).
:return: The plots (same ones you provided if you provided them)
"""
assert mode in ('live', 'static')
if isinstance(data_dict, list):
assert all(len(d) == 2 for d in data_dict), "You can provide data as a list of 2 tuples of (plot_name, plot_data)"
data_dict = OrderedDict(data_dict)
if plots is None:
plots = {k: get_plot_from_data(v, mode = mode, **plot_preference_kwargs) for k, v in data_dict.items()}
if figure is None:
if size is not None:
from pylab import rcParams
rcParams['figure.figsize'] = size
figure = plt.figure()
n_rows, n_cols = vector_length_to_tile_dims(len(data_dict))
for i, (k, v) in enumerate(data_dict.items()):
plt.subplot(n_rows, n_cols, i + 1)
plots[k].update(v)
plots[k].plot()
plt.title(k, fontdict = {'fontsize': 8})
oldhang = plt.isinteractive()
plt.interactive(not hang)
plt.show()
plt.interactive(oldhang)
return figure, plots
示例8: plot_paths
def plot_paths(results, which_to_label=None):
import matplotlib
import matplotlib.pyplot as plt
plt.clf()
interactive_state = plt.isinteractive()
xvalues = -np.log(results.lambdas[1:])
for index, path in enumerate(results.coefficients):
if which_to_label and results.indices[index] in which_to_label:
if which_to_label[results.indices[index]] is None:
label = "$x_{%d}$" % results.indices[index]
else:
label = which_to_label[results.indices[index]]
else:
label = None
if which_to_label and label is None:
plt.plot(xvalues, path[1:], ':')
else:
plt.plot(xvalues, path[1:], label=label)
plt.xlim(np.amin(xvalues), np.amax(xvalues))
if which_to_label is not None:
plt.legend(loc='upper left')
plt.title('Regularization paths ($\\rho$ = %.2f)' % results.balance)
plt.xlabel('$-\log(\lambda)$')
plt.ylabel('Value of regression coefficient $\hat{\\beta}_i$')
plt.show()
plt.interactive(interactive_state)
示例9: get_windows
def get_windows(image):
"""Display the given image and record user selected points.
Parameters
----------
image : M,N,3 ndarray
The image to be displayed.
Returns
-------
array : n_points,2
An array of coordinates in the image. Each row corresponds to the x, y
coordinates of one point. If an odd number of points are specified, the
last one will be discarded.
"""
plt.interactive(True)
plt.imshow(image)
plt.show()
crop = plt.ginput(0)
plt.close()
plt.interactive(False)
# remove last point if an odd number selected
crop = crop[:-1] if np.mod(len(crop), 2) else crop
return np.vstack(crop).astype('int')[:, [1, 0]]
示例10: draw_2D_slice_interactive
def draw_2D_slice_interactive(self, p_vals, x_variable, y_variable,
range_x, range_y, slider_ranges,
**kwargs):
previous = plt.isinteractive()
plt.ioff()
number_of_sliders = len(slider_ranges)
slider_block = 0.03*number_of_sliders
fig = plt.figure()
plt.clf()
ax = plt.axes([0.1, 0.2+slider_block, 0.8, 0.7-slider_block])
c_axs = list()
cdict = dict()
if 'color_dict' in kwargs:
cdict.update(kwargs['color_dict'])
j = 0
sliders = dict()
for i in slider_ranges:
slider_ax = plt.axes([0.1, 0.1+j*0.03, 0.8, 0.02])
slider = Slider(slider_ax, i,
log10(slider_ranges[i][0]), log10(slider_ranges[i][1]),
valinit=log10(p_vals[i]), color='#AAAAAA'
)
j += 1
sliders[i] = slider
update = SliderCallback(self, sliders, c_axs, cdict,
ax, p_vals, x_variable, y_variable, range_x, range_y,
**kwargs)
update(1)
for i in sliders:
sliders[i].on_changed(update)
plt.show()
plt.interactive(previous)
示例11: train_agent
def train_agent(mdp, agent, max_episodes, epsilon_decay=0.9, plot=False):
'''
Trains an agent on the given MDP for the specified number of episodes.
:param mdp: The mdp which implements the domain
:param agent: The RL agent to train
:param max_episodes: The maximum number of episodes to run
:param epsilon_decay: The per-episode decay rate of the epsilon parameter
:param plot: If true, plot the reward results online.
'''
episode_rewards = []
for i in range(max_episodes):
episode_rewards.append(run_episode(mdp, agent, kbd_ctl=False))
if i % 1 == 0:
agent.epsilon *= epsilon_decay
if plot:
plt.interactive(True)
plt.clf()
plt.ylabel('Reward per episodes')
plt.xlabel('Episodes')
plt.plot(episode_rewards)
plt.draw()
print "[episode %d] episode reward: %f. Epsilon now: %f" %\
(i, episode_rewards[-1], agent.epsilon)
return episode_rewards
示例12: main
def main(argv=None):
# Permit interactive use
if argv is None:
argv = sys.argv
# Parse and check incoming command line arguments
outsuffix = None
try:
try:
opts, args = getopt.getopt(argv[1:], "h", ["help"])
except getopt.error as msg:
raise Usage(msg)
for o, a in opts:
if o in ("-h", "--help"):
print(__doc__)
return 0
elif o == "-o":
outsuffix = a
except Usage as err:
print(err.msg, file=sys.stderr)
return 2
# Push interactive mode off (in case we get used from IPython)
was_interactive = plt.isinteractive()
plt.interactive(False)
# If not saving, then display.
if not outsuffix:
plt.show()
# Pop interactive mode
plt.interactive(was_interactive)
示例13: __init__
def __init__(self, client_pars=None, plot_template=None, interactive=True, **kwargs):
self.client=Client(client_pars)
self.connect()
# initialize data containers
self.pr=u.Param()
self.ob=u.Param()
self.err=[]
self.ferr=None
# initialize the plotter
from matplotlib import pyplot
self.interactive = interactive
self.pp = pyplot
pyplot.interactive(interactive)
#self.template_default = default_template
self.templates = templates
#self.template = u.Param()
self.p = u.Param(DEFAULT)
#self.update_plot_layout(plot_template=plot_template)
# save as 'cmd': tuple(ticket,buffer,key)
# will call get cmds with 'cmd', save the ticket in <ticket> and
# save the resulting data in buffer[key]
self.cmd_dct = {}
self.server_dcts={}
示例14: generate_single_funnel_test_data
def generate_single_funnel_test_data( excitation_angles, emission_angles, \
md_ex=0, md_fu=1, \
phase_ex=0, phase_fu=0, \
gr=1.0, et=1.0 ):
ex, em = np.meshgrid( excitation_angles, emission_angles )
alpha = 0.5 * np.arccos( .5*(((gr+2)*md_ex)-gr) )
ph_ii_minus = phase_ex - alpha
ph_ii_plus = phase_ex + alpha
print ph_ii_minus
print ph_ii_plus
Fnoet = np.cos( ex-ph_ii_minus )**2 * np.cos( em-ph_ii_minus )**2
Fnoet += gr*np.cos( ex-phase_ex )**2 * np.cos( em-phase_ex )**2
Fnoet += np.cos( ex-ph_ii_plus )**2 * np.cos( em-ph_ii_plus )**2
Fnoet /= (2+gr)
Fet = .25 * (1+md_ex*np.cos(2*(ex-phase_ex))) \
* (1+md_fu*np.cos(2*(em-phase_fu-phase_ex)))
Fem = et*Fet + (1-et)*Fnoet
import matplotlib.pyplot as plt
plt.interactive(True)
plt.matshow( Fem, origin='bottom' )
plt.colorbar()
示例15: interactive
def interactive(b):
b_prev = plt.isinteractive()
plt.interactive(b)
try:
yield
finally:
plt.interactive(b_prev)