本文整理汇总了Python中matplotlib.widgets.CheckButtons类的典型用法代码示例。如果您正苦于以下问题:Python CheckButtons类的具体用法?Python CheckButtons怎么用?Python CheckButtons使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CheckButtons类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _do_plot
def _do_plot(self):
stats = self._statistics.deserialize()
metrics_to_plot = self._statistics.get_metrics_to_plot()
subplots_count = len(stats)
if not subplots_count:
return
fig, axarr = plt.subplots(subplots_count)
fig.canvas.set_window_title(self._plot_title)
time = range(len(stats[stats.keys()[0]]))
axes_by_names = {}
for i, key in enumerate(stats.keys()):
axarr[i].plot(time, stats[key], label=metrics_to_plot[key].name, lw=1, color=COLORS[i])
axarr[i].set_xlabel('time (sec)')
axarr[i].set_ylabel(metrics_to_plot[key].unit.name)
axarr[i].legend()
axes_by_names[key] = i
rax = plt.axes([0.01, 0.8, 0.1, 0.1])
check_btns = CheckButtons(rax, stats.keys(), [True] * subplots_count)
check_btns.on_clicked(self._get_show_hide_fn(fig, axarr, axes_by_names))
plt.subplots_adjust(left=0.2)
plt.show()
示例2: plot_hmm_path
def plot_hmm_path(trajectory_objs, paths, legends=[], items=[]):
global colors
print_n_flush("Colors are:", colors)
for i, (trajectory, p) in enumerate(zip(trajectory_objs, paths)):
print_n_flush("Path:", p)
tr_colors = [colors[int(state)] for state in p]
t = trajectory.plot2d(color=tr_colors)
# t = plot_quiver2d(trajectory, color=tr_colors, path=p)
too_high = [tt for tt in trajectory if tt[1] > 400]
# print_n_flush( "Too high", too_high)
legends.append("Trajectory%i" % i)
# items.append(p)
items.append(t)
# gca().legend()
# Let's create checkboxes
rax = plt.axes([0.05, 0.4, 0.1, 0.15])
# rax = plt.gca()
from matplotlib.widgets import CheckButtons
check = CheckButtons(rax, legends, [True] * len(legends))
# plt.sca(axes)
def func(label):
widget = items[legends.index(label)]
widget.set_visible(not widget.get_visible())
plt.draw()
check.on_clicked(func)
示例3: __click_cb
class PeakIdentifier:
def __click_cb(self, label):
self.all_names[label] = not self.all_names[label]
def __init_fig__(self, data_name):
self.fig = figure()
self.ax = subplot(111)
self.fig.subplots_adjust(left=0.3)
title(_path.basename(data_name))
self.button_ax = plt.axes([0.05, 0.1, 0.15, 0.8])
self.check = CheckButtons(self.button_ax, sorted(self.all_names.keys()), [False] * len(self.all_names))
self.check.on_clicked(self.__click_cb)
def __init_data__(self, data, start_i, end_i, pos, pos_s):
start_i = int(start_i)
end_i = int(end_i) + 1
self.start_i = start_i
self.end_i = end_i
self.__pos = pos
self.__pos_s = pos_s
self.d = end_i - start_i
new_start = start_i - 10 * self.d
if new_start < 0:
new_start = 0
new_end = end_i + 10 * self.d
if new_end >= len(data[2]):
new_end = len(data[2] - 1)
self.new_start = new_start
self.new_end = new_end
self.xs = r_[self.new_start : self.new_end]
y1 = data[2][new_start:new_end]
y2 = data[3][new_start:new_end]
self.y = y2 - y1
def __init_plot__(self):
self.ax.axvline(self.__pos, color="m", linewidth=2)
self.ax.axvline(self.__pos - self.__pos_s, color="g")
self.ax.axvline(self.__pos + self.__pos_s, color="g")
self.ax.plot(self.xs, self.y, color="c")
self.ax.set_ylim(min(self.y), max(self.y))
self.ax.set_xlim(self.new_start, self.new_end)
def __init_names__(self, names):
self.all_names = {}
for n in names:
self.all_names[n] = False
def __init__(self, names, data, start_i, end_i, data_name, pos, pos_s):
self.__init_names__(names)
self.__init_fig__(data_name)
self.__init_data__(data, start_i, end_i, pos, pos_s)
self.__init_plot__()
def run(self):
show()
close()
return [k for k, v in self.all_names.items() if v]
示例4: plot
def plot(self, params, confidence_levels=[0.90, 0.95, 0.99], downsample=100):
from plotutils import plotutils as pu
from matplotlib import pyplot as plt
from matplotlib.widgets import CheckButtons
from itertools import cycle
lines = ['solid', 'dashed', 'dashdot', 'dotted']
linecycler = cycle(lines)
N = len(self._tracking_array)
tracking_array = self._tracking_array
param1 = tracking_array[params[0]]
param2 = tracking_array[params[1]]
pu.plot_greedy_kde_interval_2d(np.vstack([param1, param2]).T, [0.90,0.95,0.99])
ax = plt.gca()
arrows = {}
for proposal in self._proposals:
ls = next(linecycler)
sel = tracking_array['proposal'] == proposal
accepted = tracking_array['accepted'][sel]
xs = param1[sel]
ys = param2[sel]
x_ps = tracking_array[params[0]+'_p'][sel]
y_ps = tracking_array[params[1]+'_p'][sel]
dxs = x_ps - xs
dys = y_ps - ys
arrows[proposal] = []
for x, y, dx, dy, a in zip(xs,ys,dxs,dys,accepted):
if dx != 0 or dy != 0:
c = 'green' if a else 'red'
arrow = ax.arrow(x, y, dx, dy, fc=c, ec=c, alpha=0.5, visible=False, linestyle=ls)
arrows[proposal].append(arrow)
plt.subplots_adjust(left=0.5)
rax = plt.axes([0.05, 0.4, 0.4, 0.35])
check = CheckButtons(rax, self._proposals, [False for i in self._proposals])
def func(proposal):
N = len(arrows[proposal])
step = int(np.floor(N/float(downsample)))
step = step if step is not 0 else 1
for l in arrows[proposal][::step]:
l.set_visible(not l.get_visible())
plt.draw()
check.on_clicked(func)
plt.show()
示例5: __init__
def __init__(self):
self.Consistency = 'Not self consistent'
self.Bias = 0.1
self.Gate = None
self.OrbitalSel = None
self.fig, (self.axBias, self.axTrans, self.axIVCurve) = plt.subplots(3,1)
self.fig.patch.set_facecolor('ghostwhite')
plt.subplots_adjust(left=0.3)
pos = self.axBias.get_position()
self.axBias.set_position ([pos.x0, 0.55, pos.width, 0.40])
self.axTrans.set_position([pos.x0, 0.05, pos.width, 0.40])
self.axIVCurve.set_position([0.05, 0.05, 0.2, 0.3])
self.axCM = self.fig.add_axes([0.94, 0.55, 0.01, 0.35])
self.fig.canvas.mpl_connect('button_press_event', self.OnClick)
self.fig.canvas.mpl_connect('pick_event', self.OnPick)
self.fig.canvas.mpl_connect('key_press_event', self.OnPress)
self.InitMolecule()
self.InitBias()
self.InitTrans()
self.InitOrbitals()
self.InitIVCurve()
self.axSC = plt.axes([0.05, 0.85, 0.15, 0.10], axisbg='white')
self.cbSC = RadioButtons(self.axSC, ('Not self consistent', 'Hubbard', 'PPP'))
self.cbSC.on_clicked(self.UpdateConsistency)
self.axOptions1 = plt.axes([0.05, 0.7, 0.15, 0.10], axisbg='white')
self.cbOptions1 = CheckButtons(self.axOptions1, ('Overlap', 'Show Local Density','Show Local Currents'), (False, False, True))
self.cbOptions1.on_clicked(self.Options1)
self.axOptions2 = plt.axes([0.05, 0.5, 0.15, 0.15], axisbg='white')
self.cbOptions2 = CheckButtons(self.axOptions2, ('Show Transmission', 'Show Current', 'Show DOS', 'Show Orbitals', 'Show Phase'), (True, True, False, False, False))
self.cbOptions2.on_clicked(self.Options2)
c = ['seagreen', 'b', 'darkorange', 'lightsteelblue', 'm']
[rec.set_facecolor(c[i]) for i, rec in enumerate(self.cbOptions2.rectangles)]
self.axGleft = plt.axes([0.05, 0.43, 0.15, 0.02], axisbg='white')
self.axGright = plt.axes([0.05, 0.40, 0.15, 0.02], axisbg='white')
self.sGleft = Slider(self.axGleft, 'Gl', 0.0, 1.0, valinit = gLeft)
self.sGright = Slider(self.axGright, 'Gr', 0.0, 1.0, valinit = gRight)
self.sGleft.on_changed(self.UpdateG)
self.sGright.on_changed(self.UpdateG)
self.axSave = plt.axes([0.92, 0.95, 0.07, 0.04])
self.bSave = Button(self.axSave, 'Save')
self.bSave.on_clicked(self.Save)
示例6: __init__
def __init__(self, fig, rect, labels, act=None, func=None, fargs=None):
"""init function
Parameters:
fig: a matplotlib.figure.Figure instance
rect: [left, bottom, width, height]
each of which in 0-to-1-fraction i.e. 0<=x<=1
labels: array of strings
labels to be checked
act: a len(labels) array of booleans, optional, default: None
indicating whether the label is active at first
if None, all labels are inactive
func: function, optional, default: None
if not None, function called when checkbox status changes
fargs: array, optional, default: None
(optional) arguments for func
"""
self.fig = fig
self._rect = rect
self._func = func
self._fargs = fargs
self._labels = labels
self.axes = self.fig.add_axes(rect)
self.axes.set_axis_bgcolor('1.00')
inac = act if act is not None else (False,) * len(labels)
self.cb = CheckButtons(self.axes, self._labels, inac)
self.cb.on_clicked(self._onchange)
示例7: init_ax4
def init_ax4():
global ax4, checkService, checkPause, checkEndBen, checkDist, check
ax4 = fig.add_axes([.72, .15, .08, .12])
ax4.set_xticklabels([])
ax4.set_yticklabels([])
ax4.set_xticks([])
ax4.set_yticks([])
# Define checkboxes
check = CheckButtons(ax4, ('Service', 'Stepped', 'Pause', 'EndBen', 'Dist'),
(checkService, checkStepped, checkPause, checkEndBen, checkDist))
# Attach checkboxes to checkbox function
check.on_clicked(func)
示例8: __init_fig__
def __init_fig__(self, data_name):
self.fig = figure()
self.ax = subplot(111)
self.fig.subplots_adjust(left=0.3)
title(_path.basename(data_name))
self.button_ax = plt.axes([0.05, 0.1, 0.15, 0.8])
self.check = CheckButtons(self.button_ax, sorted(self.all_names.keys()), [False] * len(self.all_names))
self.check.on_clicked(self.__click_cb)
示例9: initWindow
def initWindow(self):
if not (self.args.placeOne and self.args.placeTwo):
self.randomBB()
axes().set_aspect('equal', 'datalim')
plt.subplot(2, 2, (1, 2))
plt.subplot(2, 2, (1, 2)).set_aspect('equal')
subplots_adjust(left=0.31)
subplots_adjust(bottom=-0.7)
plt.title('QSR Visualisation')
axcolor = 'lightgoldenrodyellow'
rax = plt.axes([0.03, 0.4, 0.22, 0.45], axisbg=axcolor)
checkBox = CheckButtons(rax, self.qsr_type,(False,False,False,False,False))
checkBox.on_clicked(self.EventClick)
plt.subplot(2, 2, 3)
plt.axis('off')
plt.text(1, 1, (self.__compute_qsr(self.bb1, self.bb2)), family='serif', style='italic', ha='center')
if self.qsr:
self.updateWindow()
plt.show()
示例10: _init_checks
def _init_checks(self):
self.check_labels = []
self.check_display = []
for i in range(self.n):
fn = self.config['data'][i]['filename']
label = '%s' % (os.path.basename(fn))
self.check_labels.append(label)
self.check_display.append(self.mappables[i])
self.checks = CheckButtons(self.check_ax, self.check_labels, \
self.check_display)
示例11: __init__
def __init__(self, data, auto_mask, savedir):
'''The constructor initializes all the variables and creates the plotting window.
**Input arguments:**
- *data*: NxM array
The background to be masked - an averaged (static) scattering image.
- *auto_mask*: NxM array
The default mask, masking all the bad pixels.
- *savedir*: string
Directory where the mask file will be saved.
'''
self.mask_saved = False
self.savedir = savedir
self.fig = figure()
title('Select ROI to mask. Press m to mask or w to save and exit ')
self.ax = self.fig.add_subplot(111)
# Check button for logscale switching
self.cbax = self.fig.add_axes([0.01, 0.8, 0.1, 0.15])
self.cb_log = CheckButtons(self.cbax, ('log',), (False,))
self.cb_log.on_clicked(self.toggle_logscale)
self.log_flag = False
self.canvas = self.ax.figure.canvas
#self.data = n.log10(data)
self.raw_data = data.copy()
self.data = data
self.lx, self.ly = shape(self.data)
self.auto_mask = auto_mask
self.mask = auto_mask
self.masked_data = n.ma.masked_array(self.data,self.mask)
self.points = []
self.key = []
self.x = 0
self.y = 0
self.xy = []
self.xx = []
self.yy = []
self.ind = 0
self.img = self.ax.imshow(self.masked_data,origin='lower',interpolation='nearest',animated=True)
self.colorbar = colorbar(self.img,ax=self.ax)
self.lc,=self.ax.plot((0,0),(0,0),'-+w',color='black',linewidth=1.5,markersize=8,markeredgewidth=1.5)
self.lm,=self.ax.plot((0,0),(0,0),'-+w',color='black',linewidth=1.5,markersize=8,markeredgewidth=1.5)
self.ax.set_xlim(0,self.lx)
self.ax.set_ylim(0,self.ly)
for i in range(self.lx):
for j in range(self.ly):
self.points.append([i,j])
cidb = connect('button_press_event', self.on_click)
cidk = connect('key_press_event',self.on_click)
cidm = connect('motion_notify_event',self.on_move)
示例12: __init__
def __init__(self, field, fieldname, halospec=None):
"""Initializes a visualization instance, that is a windows with a field
field is a 3D numpy array
fieldname is a string with the name of the field
halospec is a 2x2 array with the definition of the halo size
After this call the window is shown
"""
self.field = field
self.fieldname = fieldname
# Register halo information
if halospec is None:
halospec = [[3, 3], [3, 3]]
self.istart = halospec[0][0]
self.iend = field.shape[0] - halospec[0][1]
self.jstart = halospec[1][0]
self.jend = field.shape[1] - halospec[1][1]
self.plotHalo = True
self.plotLogLog = False
self.curklevel = 0
self.figure = plt.figure()
# Slider
slideraxes = plt.axes([0.15, 0.02, 0.5, 0.03], axisbg="lightgoldenrodyellow")
self.slider = Slider(slideraxes, "K level", 0, field.shape[2] - 1, valinit=0)
self.slider.valfmt = "%2d"
self.slider.set_val(0)
self.slider.on_changed(self.updateSlider)
# CheckButton
self.cbaxes = plt.axes([0.8, -0.04, 0.12, 0.15])
self.cbaxes.set_axis_off()
self.cb = CheckButtons(self.cbaxes, ("Halo", "Logscale"), (self.plotHalo, self.plotLogLog))
self.cb.on_clicked(self.updateButton)
# Initial plot
self.fieldaxes = self.figure.add_axes([0.1, 0.15, 0.9, 0.75])
self.collection = plt.pcolor(self._getField(), axes=self.fieldaxes)
self.colorbar = plt.colorbar()
self.fieldaxes.set_xlim(right=self._getField().shape[1])
self.fieldaxes.set_ylim(top=self._getField().shape[0])
plt.xlabel("i")
plt.ylabel("j")
self.title = plt.title("%s - Level 0" % (fieldname,))
plt.show(block=False)
示例13: _recreate_show_lines_check_button
def _recreate_show_lines_check_button(self):
axcolor = "lightgoldenrodyellow"
if hasattr(self, "rax_showlines"):
self.rax_showlines.cla()
self.rax_showlines = plt.axes([0.2, 0.05, self.button_length__, self.button_height__], axisbg=axcolor)
visible = self.prop_ifs.holder.get_visible()
linestyle = self.prop_ifs.holder.get_linestyle()
labels = ("hide ifs", "markers", "edges", "labels")
actives = (self.prop_ifs.hide_ifs, visible, linestyle not in ["None", None], self.prop_ifs.show_ann)
self.holder_actives = dict(zip(labels, actives))
self.w_check_components = CheckButtons(self.rax_showlines, labels, actives)
self.w_check_components.on_clicked(self.update_show_components)
return self.w_check_components
示例14: _recreate_show_lines_check_button
def _recreate_show_lines_check_button(self):
if self.ax_active not in self.active_lines_idx.keys():
return None
axcolor = 'lightgoldenrodyellow'
if hasattr(self, 'rax_showlines'):
self.rax_showlines.cla()
self.rax_showlines = plt.axes([0.2, 0.05,
self.button_length__,
self.button_height__], axisbg=axcolor)
prop_ifs = self._prop_idx_active[self.line_active__]
visible = prop_ifs.holder.get_visible()
linestyle = prop_ifs.holder.get_linestyle()
self.w_check_components = CheckButtons(self.rax_showlines,
('markers', 'edges', 'labels'),
(visible, linestyle not in ['None', None], prop_ifs.show_ann))
self.w_check_components.on_clicked(self.update_show_components)
return self.w_check_components
示例15: __init__
def __init__(self):
self.data = 0
self.errors = 0
self.tBins = 0
self.fig = plt.figure(1)
self.ax = self.fig.add_subplot(111,title="Pulse Display")
self.fig.subplots_adjust(left=0.3)
self.numPulse = 1
self.flcFlag = False
self.timeOffset = 0.0
self.currentModelName=[]
self.tMaxSelector = 0
self.resultAx =False
self.useSelector = False
#check if a pulseModSelector has been passed
self.pms = False
self.radio = False
ax = plt.axes([.05, 0.05, 0.12, 0.08])
self.addButton = Button(ax,'Add Pulse',color='0.95', hovercolor='0.45')
self.addButton.on_clicked(self.AddPulse)
ax2 = plt.axes([.05, 0.15, 0.12, 0.08])
self.findMaxButton = Button(ax2,'Find Max',color='0.95', hovercolor='0.45')
self.findMaxButton.on_clicked(self.FindMax)
ax3 = plt.axes([.05, 0.25, 0.12, 0.08])
self.fitButton = Button(ax3,'Fit',color='0.95', hovercolor='0.45')
self.fitButton.on_clicked(self.FitPulse)
ax4 = plt.axes([.05, 0.45, 0.12, 0.08])
self.useSelectorCheck = CheckButtons(ax4, ["Selector"], [False] )
self.useSelectorCheck.on_clicked(self.UseSelector)