我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用matplotlib.widgets.CheckButtons()。
def _draw_proj_checkbox(event, params, draw_current_state=True): """Toggle options (projectors) dialog""" from matplotlib import widgets projs = params['projs'] # turn on options dialog labels = [p['desc'] for p in projs] actives = ([p['active'] for p in projs] if draw_current_state else [True] * len(params['projs'])) width = max([len(p['desc']) for p in projs]) / 6.0 + 0.5 height = len(projs) / 6.0 + 0.5 fig_proj = figure_nobar(figsize=(width, height)) fig_proj.canvas.set_window_title('SSP projection vectors') params['fig_proj'] = fig_proj # necessary for proper toggling ax_temp = fig_proj.add_axes((0, 0, 1, 1), frameon=False) proj_checks = widgets.CheckButtons(ax_temp, labels=labels, actives=actives) # change already-applied projectors to red for ii, p in enumerate(projs): if p['active'] is True: for x in proj_checks.lines[ii]: x.set_color('r') # make minimal size # pass key presses from option dialog over proj_checks.on_clicked(partial(_toggle_proj, params=params)) params['proj_checks'] = proj_checks # this should work for non-test cases try: fig_proj.canvas.draw() fig_proj.show(warn=False) except Exception: pass