本文整理汇总了Python中matplotlib.widgets.Button.on_clicked方法的典型用法代码示例。如果您正苦于以下问题:Python Button.on_clicked方法的具体用法?Python Button.on_clicked怎么用?Python Button.on_clicked使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.widgets.Button
的用法示例。
在下文中一共展示了Button.on_clicked方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from matplotlib.widgets import Button [as 别名]
# 或者: from matplotlib.widgets.Button import on_clicked [as 别名]
def __init__(self, image_sequence):
# Fix the size of subplot
self.fig, self.axes = plt.subplots(2, sharey=True, figsize=(10, 5))
# Set background to be gray
self.fig.patch.set_facecolor('#333333')
# Store image sequence in self.seq and display the sequence
self.seq = image_sequence
self.image = self.seq.init_image()
self.image2 = self.seq.init_image_original()
self.image_figure = plt.subplot2grid((3, 3), (0, 0), colspan=3, rowspan=2)
self.image_figure.axis('off')
self.image_plot = self.image_figure.imshow(self.image)
self.image_figure.set_title('Dinic', color='white')
self.init_figure = plt.subplot2grid((3, 3), (2, 1))
self.init_figure.axis('off')
self.init_plot = plt.imshow(self.image2)
self.init_figure.set_title('Flow Graph', color = 'white' )
self.text_figure = plt.subplot2grid((3, 3), (2, 2))
self.text_figure.axis('off')
self.text_figure.set_title('',color = 'white')
plt.subplots_adjust(bottom=0.2)
axnext = plt.axes([0.81, 0.05, 0.1, 0.075])
bnext = Button(axnext, 'Next')
bnext.on_clicked(self.next)
plt.show()
示例2: setup_controls
# 需要导入模块: from matplotlib.widgets import Button [as 别名]
# 或者: from matplotlib.widgets.Button import on_clicked [as 别名]
def setup_controls(self):
""" Set up button axes"""
buttons = [[('Auto levels', self.do_autolevels),
('Levels1', self.do_levels_test),
('Oldie', self.do_levels_old),
('Clip', self.do_levels_clip)],
[('Blur uniform', self.do_blur),
('Blur gaussian', self.do_blur_gaussian),
('Sharpen', self.do_sharpen),
('Unsharp', self.do_unsharp),
('Edge detection', self.do_edges)],
[('Apply', self.apply),
('Reset', self.reset),
('Save', self.save),
('Quit', self.quit)]]
max_cols = max(len(row) for row in buttons)
padding = 0.01
start, end = 0.03, 0.97
hspace = (end - start) / max_cols
row_height = 0.03
vspace = row_height + 0.003
for j, row in enumerate(buttons):
for i, b in enumerate(row):
box = [start + i*hspace, 0.01 + j*vspace,
hspace - padding, row_height]
print box
axis = self.fig.add_axes(box)
button = Button(axis, b[0])
self.axes.append(axis)
button.on_clicked(b[1])
self.buttons.append(button)
示例3: main
# 需要导入模块: from matplotlib.widgets import Button [as 别名]
# 或者: from matplotlib.widgets.Button import on_clicked [as 别名]
def main():
from matplotlib import pyplot as plt
import utils
fig = utils.createfig()
a = WSin(fig, [0.1, 0.5, 0.8, 0.3] , nps=5)
b = WSin(fig, [0.1, 0.1, 0.8, 0.3], nps=3, om=3)
args11 = (dict(k=0, am=1, ph=0, t='v', n='1'),
dict(k=-1.5, am=0.1, ph=0.5, t='v', n='3'),)
args12 = (dict(k=1,am=2,ph=1,t='i',n='2'),)
args13 = (dict(k=100,am=3,ph=2,t='i',n='no',v=False),)
args2 = (dict(k=0,am=1,ph=0,t='v',n='1'),dict(k=1,am=2,ph=1,t='i',n='2'),
dict(k=-1.5,am=0.1,ph=0,t='v',n='3'),\
dict(k=100,am=3,ph=2,t='i',n='no',v=False),)
a.new(100, args11, args12, ())
b.new(101, *args2)
#b.set_anim(True)
# bottone
from matplotlib.widgets import Button
box = fig.add_axes([0.05, 0.90, 0.05, 0.05])
but = Button(box, 'next')
def func(wtf):
#args2 = _r_args(4)
#print args2
#b.new(100, *args2)
b.set_anim(not b.get_anim())
but.on_clicked(func)
plt.show()
示例4: pick_cest
# 需要导入模块: from matplotlib.widgets import Button [as 别名]
# 或者: from matplotlib.widgets.Button import on_clicked [as 别名]
def pick_cest(args):
if len(args.experiments) > 1:
sys.exit(
"\nError: Multiple experiment files were given. 'chemex pick_cest' "
"should only be run with a single experiment files.\n"
)
# Read experimental setup and data
data = datasets.read_data(args)
if not data.data[0].experiment_name.startswith("cest"):
sys.exit(
"\nError: The command 'chemex pick_cest' only works with CEST "
"experiments.\n"
)
callback = Buttons(data, args.out_dir)
axprevious = plt.axes([0.825, 0.1, 0.075, 0.075])
axnext = plt.axes([0.9, 0.1, 0.075, 0.075])
bprevious = Button(axprevious, "Previous")
bprevious.on_clicked(callback.previous)
bnext = Button(axnext, "Next")
bnext.on_clicked(callback.next)
plt.show()
示例5: param_gui
# 需要导入模块: from matplotlib.widgets import Button [as 别名]
# 或者: from matplotlib.widgets.Button import on_clicked [as 别名]
def param_gui(letter_name, shapeModeler):
global sliders, mainPlot, fig, pca_params
fig, ax = plt.subplots()
whiteSpace = 0.15 + num_params*0.05
plt.subplots_adjust( bottom=whiteSpace)
plt.axis('equal')
#plot of initial shape
params = np.zeros((num_params,1))
shape = shapeModeler.makeShape(params)
shape = ShapeModeler.normaliseShape(shape)
numPointsInShape = len(shape)/2
x_shape = shape[0:numPointsInShape]
y_shape = shape[numPointsInShape:]
mainPlot, = plt.plot(x_shape, -y_shape)
plt.axis([-1, 1, -1, 1],autoscale_on=False, aspect='equal')
plt.title(letter_name)
#add sliders to modify parameter values
parameterVariances = shapeModeler.getParameterVariances()
sliders = [0]*num_params
for i in range(num_params):
slider = Slider(plt.axes([0.25, 0.1+0.05*(num_params-i-1), 0.65, 0.03], axisbg=axcolor),
'Parameter '+str(i+1), -5*parameterVariances[i], 5*parameterVariances[i], valinit=0)
slider.on_changed(partial(update, shapeModeler))
sliders[i] = slider
resetax = plt.axes([0.8, 0.025, 0.1, 0.04])
button = Button(resetax, 'Reset', color=axcolor, hovercolor='0.975')
button.on_clicked(reset)
plt.show()
return pca_params
示例6: slider
# 需要导入模块: from matplotlib.widgets import Button [as 别名]
# 或者: from matplotlib.widgets.Button import on_clicked [as 别名]
class slider():
def __init__(self,res):
self.res=res
def slider_bar(self,res):
#setupthe slider
axcolor = 'lightgoldenrodyellow'
self.axtime = plt.axes([0.1, 0.05, 0.8, 0.03], axisbg=axcolor)
self.stime = Slider(self.axtime, 'Timestep', 0, len(res.resobj.fils.fid.dimensions['Time']), valinit=0)
def update(val,res):
t = self.stime.val
res.refresh_plot(t)
self.stime.on_changed(update(self,res))
def foward_button(self,res):
self.fwdax = plt.axes([0.1, 0.1, 0.1, 0.04])
self.fwdb = Button(self.fwdax, 'forward', color='lightgoldenrodyellow', hovercolor='0.975')
self.fwdb.on_clicked(slider.update(res.resobj.timestep-1,res))
示例7: main
# 需要导入模块: from matplotlib.widgets import Button [as 别名]
# 或者: from matplotlib.widgets.Button import on_clicked [as 别名]
def main():
global ax
fig = plt.figure()
bhandler = ButtonHandler()
mhandler = MouseHandler()
axclear = plt.axes([0.37, 0.02, 0.1, 0.075])
axload = plt.axes([0.48, 0.02, 0.1, 0.075])
axsave = plt.axes([0.59, 0.02, 0.1, 0.075])
axcreate = plt.axes([0.7, 0.02, 0.1, 0.075])
axrun = plt.axes([0.81, 0.02, 0.1, 0.075])
bclear = Button(axclear, 'CLEAR')
bclear.on_clicked(bhandler.clear)
bload = Button(axload, 'LOAD')
bload.on_clicked(bhandler.load_data)
bsave = Button(axsave, 'SAVE')
bsave.on_clicked(bhandler.save_data)
bcreate = Button(axcreate, 'CREATE')
bcreate.on_clicked(bhandler.create_polygon)
brun = Button(axrun, 'RUN')
brun.on_clicked(bhandler.run_triangulation)
ax = fig.add_subplot(111, autoscale_on=False)
cid = fig.canvas.mpl_connect('button_press_event', mhandler.onclick)
plt.show()
示例8: debug_plot
# 需要导入模块: from matplotlib.widgets import Button [as 别名]
# 或者: from matplotlib.widgets.Button import on_clicked [as 别名]
def debug_plot(a, b, nodes, fs, coeffs):
global _debug_fig, _debug_cancelled
if _debug_cancelled:
return
if 'show' not in locals():
from pylab import axes, subplot, subplots_adjust, figure, draw, plot, axvline, xlim, title, waitforbuttonpress, gcf
from matplotlib.widgets import Button
if _debug_fig is None:
#curfig = gcf()
#print dir(curfig)
_debug_fig = figure()
ax = _debug_fig.add_subplot(111)
#subplots_adjust(bottom=0.15)
butax = axes([0.8, 0.015, 0.1, 0.04])
button = Button(butax, 'Debug', hovercolor='0.975')
def debug(event):
import pdb; pdb.set_trace()
button.on_clicked(debug)
_debug_fig.sca(ax)
draw()
#figure(curfig)
_debug_fig.gca().clear()
plot(nodes, fs, linewidth=5, figure = _debug_fig)
axvline(a, color="r", figure = _debug_fig)
axvline(b, color="r", figure = _debug_fig)
d = 0.05 * (b-a)
_debug_fig.gca().set_xlim(a-d, b+d)
title("press key in figure for next debugplot or close window to continue")
try:
while not _debug_cancelled and not _debug_fig.waitforbuttonpress(-1):
pass
except:
_debug_cancelled = True
示例9: ButtonClickProcessor
# 需要导入模块: from matplotlib.widgets import Button [as 别名]
# 或者: from matplotlib.widgets.Button import on_clicked [as 别名]
class ButtonClickProcessor(object):
def __init__(self, axes, label, color, viewer):
self.groups = viewer.groups
self.fig_text = viewer.fig_text
self.button = Button(axes, label=label, color=color)
self.button.on_clicked(self.print_group)
def print_group(self, event):
print(self.button.label.get_text())
group = self.groups[int(self.button.label.get_text())]
self.fig_text.clf()
self.ax_text = self.fig_text.add_subplot(111)
# plt.rcParams['text.usetex'] = True
y_write = np.linspace(0, 0.9, len(group.keys()))
for ii, key in enumerate(group.keys()):
self.ax_text.text(0, y_write[ii], str(key) + ' : ' + str(group[key]), fontsize=15, fontstyle='oblique')
#Show it
self.fig_text.canvas.draw()
示例10: __init__
# 需要导入模块: from matplotlib.widgets import Button [as 别名]
# 或者: from matplotlib.widgets.Button import on_clicked [as 别名]
class NavField:
def __init__(self, pltinfo):
self.fld = -1
self.nflds = len(pltinfo.selindices['field'])
self.pltinfo = pltinfo
prevwidth = 0.13
nextwidth = 0.12
butheight = 0.05
butleft = 0.7
butbot = 0.025
butgap = 0.5 * butbot
self.nextloc = [butleft + prevwidth + butgap,
butbot, nextwidth, butheight]
self.prevloc = [butleft, butbot, prevwidth, butheight]
self.inactivecolor = '#99aaff'
self.activecolor = '#aaffcc'
def _draw_buts(self):
if self.fld < self.nflds - 1:
axnext = pl.axes(self.nextloc)
self.bnext = Button(axnext, 'Next fld >',
color=self.inactivecolor,
hovercolor=self.activecolor)
self.bnext.on_clicked(self.next)
if self.fld > 0:
axprev = pl.axes(self.prevloc)
self.bprev = Button(axprev, '< Prev fld',
color=self.inactivecolor,
hovercolor=self.activecolor)
self.bprev.on_clicked(self.prev)
#pl.show()
def _do_plot(self):
didplot = plotfield(self.pltinfo.selindices['field'][self.fld],
self.pltinfo)
if didplot:
self._draw_buts()
return didplot
def next(self, event):
didplot = False
startfld = self.fld
while self.fld < self.nflds - 1 and not didplot:
self.fld += 1
didplot = self._do_plot()
if not didplot:
print "You are on the last field with any selected baselines."
self.fld = startfld
#plotfield(self.pltinfo.selindices['field'][self.fld],
# self.pltinfo, self.mytb)
def prev(self, event):
didplot = False
startfld = self.fld
while self.fld > 0 and not didplot:
self.fld -= 1
didplot = self._do_plot()
if not didplot:
print "You are on the first field with any selected baselines."
self.fld = startfld
示例11: __init__
# 需要导入模块: from matplotlib.widgets import Button [as 别名]
# 或者: from matplotlib.widgets.Button import on_clicked [as 别名]
def __init__(self):
'''variable definitions'''
SEGMENTS = int(3) #number of segments
#could probably make these lists instead of arrays
self.l = np.array([0, 100, 100, 80])# actual measurements of segment length in mm
self.w = np.array([0]*SEGMENTS,dtype=float) #horizontal coordinate
self.z = np.array([0]*SEGMENTS,dtype=float) #vertical coordinate
self.x = np.array([0]*SEGMENTS,dtype=float) #x axis components
self.y = np.array([0]*SEGMENTS,dtype=float) #y axis components
self.a = np.array([np.pi]*SEGMENTS,dtype=float) #angle for the link, reference is previous link
self.gripper_angle = np.array([0, -45, -90, 45, 90])#preselected gripper angles
self.current_gripper = 2 #gripper angle selection
self.tw = 30.0 # w axis position depth
self.tz = 20.0 # z axis starting position height
self.l12 = 0.0 # hypotenuse belween a1 & a2
self.a12 = 0.0 #inscribed angle between hypotenuse, w
self.fig = plt.figure("CS 4TE3 Robot Simulator") #create the frame
self.ax = plt.axes([0.05, 0.2, 0.90, .75], projection='3d') #3d ax panel
self.axe = plt.axes([0.25, 0.85, 0.001, .001])#panel for error message
self.count = 0
self.coords = ((20,30),(50,60),(30,40),(70,100),(70,150))
self.display_error()
self.draw_robot()
butval = plt.axes([0.35, 0.1, 0.1, 0.075])
but = Button(butval, 'move')
but.on_clicked(self.move_click)
#error = dist(1,2);
#print (error)
plt.show()#end of constructor
示例12: plot
# 需要导入模块: from matplotlib.widgets import Button [as 别名]
# 或者: from matplotlib.widgets.Button import on_clicked [as 别名]
def plot(self):
self.update_current()
# maximize window
figManager = plt.get_current_fig_manager()
figManager.window.showMaximized()
self.fig.canvas.mpl_connect('button_press_event', self.onclick)
self.fig.canvas.mpl_connect('key_press_event', self.onpress)
finishax = plt.axes([0.83, 0.85, 0.15, 0.1])
finishbutton = Button(finishax, 'Finish', hovercolor='0.975')
finishbutton.on_clicked(self.finish)
closeax = plt.axes([0.83, 0.65, 0.15, 0.1])
button = Button(closeax, 'Replace (m)', hovercolor='0.975')
button.on_clicked(self.replace_b)
nextax = plt.axes([0.83, 0.45, 0.15, 0.1])
nextbutton = Button(nextax, 'Next (n)', hovercolor='0.975')
nextbutton.on_clicked(self.next_go)
deleteax = plt.axes([0.83, 0.25, 0.15, 0.1])
delete_button = Button(deleteax, 'Delete (j)', hovercolor='0.975')
delete_button.on_clicked(self.delete_b)
undoax = plt.axes([0.83, 0.1, 0.15, 0.1])
undo_button = Button(undoax, 'Undo (u)', hovercolor='0.975')
undo_button.on_clicked(self.undo_b)
plt.show()
return
示例13: preparePlot
# 需要导入模块: from matplotlib.widgets import Button [as 别名]
# 或者: from matplotlib.widgets.Button import on_clicked [as 别名]
def preparePlot(shapeModeler):
global sliders, mainPlot, fig
fig, ax = plt.subplots();
whiteSpace = 0.15 + numParams*0.05;
plt.subplots_adjust( bottom=whiteSpace);
plt.axis('equal');
#plot of initial shape
params = np.zeros((numParams,1));
shape = shapeModeler.makeShape(params);
shape = ShapeModeler.normaliseShape(shape);
numPointsInShape = len(shape)/2;
x_shape = shape[0:numPointsInShape];
y_shape = shape[numPointsInShape:];
mainPlot, = plt.plot(x_shape, -y_shape);
plt.axis([-1, 1, -1, 1],autoscale_on=False, aspect='equal');
#add sliders to modify parameter values
parameterVariances = shapeModeler.getParameterVariances();
sliders = [0]*numParams;
for i in range(numParams):
slider = Slider(plt.axes([0.25, 0.1+0.05*(numParams-i-1), 0.65, 0.03], axisbg=axcolor),
'Parameter '+str(i+1), -5*parameterVariances[i], 5*parameterVariances[i], valinit=0);
slider.on_changed(update);
sliders[i] = slider;
resetax = plt.axes([0.8, 0.025, 0.1, 0.04])
button = Button(resetax, 'Reset', color=axcolor, hovercolor='0.975')
button.on_clicked(reset)
plt.show()
示例14: setup_plot
# 需要导入模块: from matplotlib.widgets import Button [as 别名]
# 或者: from matplotlib.widgets.Button import on_clicked [as 别名]
def setup_plot():
global rate_slider, delta_slider, fig, ax, l, radio
fig, ax = plt.subplots()
ax.grid('on')
plt.subplots_adjust(left=0.25, bottom=0.25)
moneyFmt = FuncFormatter(money)
ax.yaxis.set_major_formatter(moneyFmt)
s = calc_compounding( rate, periods, principal, contribution, delta,inflation)
t = np.arange(2014, (2014+periods))
l, = plt.plot(t,s, lw=2, color='red')
plt.ylabel("Investment Loss (FV)")
plt.axis([2014, (2014+periods), 0, principal])
plt.axis('tight')
axfreq = plt.axes([0.25, 0.1, 0.65, 0.03], axisbg=axcolor)
axamp = plt.axes([0.25, 0.15, 0.65, 0.03], axisbg=axcolor)
rate_slider = Slider(axfreq, 'Avg.Returns', 4, 8, valinit=rate)
delta_slider = Slider(axamp, 'Delta', 0.1, 1, valinit=delta)
resetax = plt.axes([0.8, 0.025, 0.1, 0.04])
button = Button(resetax, 'Reset', color=axcolor, hovercolor='0.975')
rate_slider.on_changed(update)
delta_slider.on_changed(update)
button.on_clicked(reset)
rax = plt.axes([0.015, 0.15, 0.15, 0.15], axisbg=axcolor)
radio = RadioButtons(rax, ('0','3000', '6000', '9000'), active=0)
radio.on_clicked(contribution_update)
plt.show()
return rate_slider,delta_slider,fig,ax,l,radio
示例15: __init__
# 需要导入模块: from matplotlib.widgets import Button [as 别名]
# 或者: from matplotlib.widgets.Button import on_clicked [as 别名]
def __init__(self, size = (20, 200), inside = "random"):
self.filter = fp = np.array([[1, 1, 1],
[1, 0, 1],
[1, 1, 1]], np.uint8)
self.in_process = False
self.fig = plt.figure()
# self.fig, self.ax = plt.subplots(figsize=(6,7),)
# self.animation_ax = plt.subplot2grid((6,7), (0, 0), colspan=6, rowspan=6)
# button_ax = plt.subplot2grid((6,7), (0, 6), rowspan=1)
# button_1ax = plt.subplot2grid((6,7), (1, 6), rowspan=1)
self.animation_ax = self.fig.add_axes([.05, .05, .8, .9])
self.animation_ax.axis('off')
# sld_size_ax = self.fig.add_axes([.85, .3, .15, .03])
# sld_size = Slider(sld_size_ax, 'Size', size[0], size[1], valinit=np.mean(size), valfmt=u'%0.0f', dragging=True)
# sld_size.on_changed(self.sld_size_callback)
btn_draw_ax = self.fig.add_axes([.85, .2, .1, .1])
btn_draw = Button(btn_draw_ax, 'ginput')
btn_draw.on_clicked(self.btn_draw_callback)
button_1ax = self.fig.add_axes([.85, .1, .1, .1])
goutput = Button(button_1ax, 'goutput')
goutput.on_clicked(self.goutput_callback)
self.size = np.mean(size)
if inside == "random":
self.field = np.random.randint(2, size=(self.size,self.size))
elif inside == "empty":
self.field = np.zeros((self.size, self.size))
self.im = self.animation_ax.imshow(self.field, cmap=plt.cm.gray, interpolation='nearest')