本文整理汇总了Python中matplotlib.widgets.RadioButtons类的典型用法代码示例。如果您正苦于以下问题:Python RadioButtons类的具体用法?Python RadioButtons怎么用?Python RadioButtons使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RadioButtons类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_controls
def _create_controls(self):
self._freq_ax = plt.axes([0.2, 0.19, 0.2, 0.03])
self._freq_slider = Slider(self._freq_ax,
'Frequency',
0,
self.samplerate / 2.0,
valinit = self.frequency)
self._freq_slider.on_changed(self.set_signal_frequency)
self._ampl_ax = plt.axes([0.2, 0.1, 0.2, 0.03])
self._ampl_slider = Slider(self._ampl_ax,
'Amplitude',
-100,
0,
valinit = dcv.lin2db(self.amplitude))
self._ampl_slider.on_changed(self.set_signal_amplitude)
self._signaltype_ax = plt.axes([0.5, 0.05, 0.15, 0.20])
self._signaltype_radio = RadioButtons(self._signaltype_ax,
('Sine', 'Square', 'Sawtooth',
'Triangle', 'Noise', 'Constant'))
self._signaltype_radio.on_clicked(self.set_signal_type)
self._windowtype_ax = plt.axes([0.7, 0.05, 0.15, 0.20])
self._windowtype_radio = RadioButtons(self._windowtype_ax,
('Flat', 'Hanning', 'Hamming', 'Blackman'))
self._windowtype_radio.on_clicked(self.set_window_type)
示例2: slide_ddg
def slide_ddg(args):
global new_df, radio, color_by, picked
global scat, ax, sliders, sc_df, fig, cm, cbar
sc_df = Rf.score_file2df(args['sc'], args['names'])
args['logger'].log('score file has %i entries' % len(sc_df))
if args['pc'] is not None:
pc_df = get_rmsds_from_table(args['pc'])
args['logger'].log('pc file had %i entries' % len(pc_df))
a = sc_df.merge(pc_df, on='description')
args['logger'].log('combined there are %i entries' % len(a))
sc_df = a.copy()
if args['percent'] != 100:
threshold = np.percentile(sc_df[args['y']], args['percent'])
sc_df = sc_df[ sc_df[args['y']] < threshold ]
color_by = args['y']
picked = False
new_df = sc_df.copy()
fig, ax = plt.subplots()
plt.subplots_adjust(left=0.25, bottom=0.25)
cm = plt.cm.get_cmap('RdYlBu')
scat = ax.scatter(sc_df[args['x']].values, sc_df[args['y']].values, s=40, cmap=cm, c=sc_df[color_by], picker=True)
cbar = plt.colorbar(scat)
sliders = {}
for i, term in enumerate(args['terms']):
slider_ax = plt.axes([0.25, 0.01+i*0.035, 0.65, 0.03])
sliders[term] = Slider(slider_ax, term, np.min(sc_df[term].values), np.max(sc_df[term].values), 0)
sliders[term].on_changed(update)
ax.set_xlim(np.min(new_df[args['x']].values)-1, np.max(new_df[args['x']].values)+1)
ax.set_ylim(np.min(new_df[args['y']].values)-1, np.max(new_df[args['y']].values)+1)
ax.set_xlabel(args['x'])
ax.set_ylabel(args['y'])
resetax = plt.axes([0.025, 0.7, 0.15, 0.15]) #[0.8, 0.025, 0.1, 0.04])
button = Button(resetax, 'Reset', color='lightgoldenrodyellow', hovercolor='0.975')
button.on_clicked(reset)
printax = plt.axes([0.025, 0.3, 0.15, 0.15])
printbutton = Button(printax, 'Print', color='green', hovercolor='red')
printbutton.on_clicked(print_table)
logax = plt.axes([0.025, 0.1, 0.15, 0.15])
logbutton = Button(logax, 'log table', color='blue', hovercolor='red')
logbutton.on_clicked(log_table)
rax = plt.axes([0.025, 0.5, 0.15, 0.15], axisbg='white')
radio = RadioButtons(rax, args['terms'], active=0)
radio.on_clicked(colorfunc)
# cbar = plt.colorbar(scat)
pl = PointLabel(new_df, ax, fig, args['x'], args['y'], ['description', 'a_sasa', 'a_res_solv', 'a_pack', 'a_span_topo', 'a_ddg', 'fa_elec'], args['logger'])
fig.canvas.mpl_connect('pick_event', pl.onpick)
plt.show()
示例3: setup_plot
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
示例4: WidgetsBasic
class WidgetsBasic(WidgetsSimple):
def __init__(self, canvas=None, active_prop=None):
super(WidgetsBasic, self).__init__(canvas, active_prop)
self.colors_ifs = {}
@property
def prop_ifs(self):
return self.active_prop
def update_show_components(self, label):
super(WidgetsBasic, self).update_show_components(label)
if label == "hide ifs":
if self.holder_actives[label]:
self.prop_ifs.holder.set_linestyle(" ")
self.prop_ifs.holder.set_visible(False)
self.prop_ifs.set_visible_annotations(False)
self.prop_ifs.topo_const.set_visible(False)
else:
self.prop_ifs.holder.set_linestyle(" ")
self.prop_ifs.holder.set_visible(True)
self.prop_ifs.set_visible_annotations(True)
self.prop_ifs.topo_const.set_visible(True)
# here is updated the active prop_ifs
def recreate_widgets(self, idx_active, props, active_prop):
super(WidgetsBasic, self).recreate_widgets_(active_prop)
self._recreate_active_ifs_radiobutton(idx_active, props)
def _recreate_active_ifs_radiobutton(self, idx_active, props):
self.props = props
axcolor = "lightgoldenrodyellow"
if hasattr(self, "rax_activeifs"):
self.rax_activeifs.cla()
self.rax_activeifs = plt.axes(
[0.2 + self.button_length__ + 0.01, 0.05, self.button_length__, self.button_height__], axisbg=axcolor
)
activecolor = self.active_prop.get_color()
self.w_rad_active_ifs = RadioButtons(
self.rax_activeifs, sorted(self.colors_ifs.keys()), active=idx_active, activecolor=activecolor
)
self.w_rad_active_ifs.on_clicked(self.colorfunc)
return self.w_rad_active_ifs
def colorfunc(self, label):
idx = int(label)
self.active_prop = self.props[idx]
self.w_rad_active_ifs.activecolor = self.prop_ifs.get_color()
self._recreate_radius_slider()
self._recreate_show_lines_check_button()
self._recreate_alpha_slider()
self._recreate_textsize_slider()
if self.canvas is None:
self.canvas.draw()
示例5: run_main
def run_main(A,B,C,dA,dB,dC):
plt.close()
plt.figure()
int_writer()
var_writer_uncert(A,B,C)
run_SPCAT()
data = cat_reader()
t = []
s = []
for x in data:
s.append(0.0)
s.append(str(10**float(x[1])))
s.append(0.0)
t.append(float(x[0])-0.0001)
t.append(x[0])
t.append(float(x[0])+0.0001)
ax = plt.subplot(111)
plt.subplots_adjust(left=0.25, bottom=0.25)
a0 = 5
f0 = 3
global l
l, = plt.plot(t,s, lw=2, color='red')
#plt.axis([0, 1, -10, 10])
axcolor = 'lightgoldenrodyellow'
axA = plt.axes([0.25, 0.15, 0.65, 0.03], axisbg=axcolor)
axB = plt.axes([0.25, 0.1, 0.65, 0.03], axisbg=axcolor)
axC = plt.axes([0.25, 0.05, 0.65, 0.03], axisbg=axcolor)
global A_slider
global B_slider
global C_slider
A_slider = Slider(axA, 'A', A-dA, A+dA, valinit=A)
B_slider = Slider(axB, 'B', B-dB, B+dB, valinit=B)
C_slider = Slider(axC, 'C', C-dC, C+dC, valinit=C)
A_slider.on_changed(update)
B_slider.on_changed(update)
C_slider.on_changed(update)
global button
global radio
resetax = plt.axes([0.1, 0.025, 0.1, 0.04])
button = Button(resetax, 'Reset', color=axcolor, hovercolor='0.975')
button.on_clicked(reset)
rax = plt.axes([0.025, 0.5, 0.15, 0.15], axisbg=axcolor)
radio = RadioButtons(rax, ('red', 'blue', 'green'), active=0)
radio.on_clicked(colorfunc)
plt.show()
示例6: _create_plot_controls
def _create_plot_controls(self):
self._dbrax = plt.axes([0.12, 0.05, 0.10, 0.10])
self._dbradio = RadioButtons(self._dbrax, ('Amplitude', 'Phase'))
self._dbradio.on_clicked(self.set_plot_style)
self._rax = plt.axes([0.25, 0.03, 0.15, 0.20])
self._radio = RadioButtons(self._rax, ('Low Pass', 'High Pass'))
self._radio.on_clicked(self.set_biquad_type)
self._sfax = plt.axes([0.6, 0.19, 0.2, 0.03])
self._fcslider = Slider(self._sfax, 'Cut-off frequency', 0, self._bq_fs/2, valinit = self._bq_fc)
self._fcslider.on_changed(self.set_biquad_frequency_cutoff)
示例7: _GUI_display
def _GUI_display(self,redshift_est,ztest,corr_val,wave,flux_sc):
'''Display the spectrum and reference lines.'''
self.fig = plt.figure(figsize=(10, 8))
gs = gridspec.GridSpec(2, 1, height_ratios=[2, 1])
ax2 = plt.subplot(gs[0])
ax = plt.subplot(gs[1])
plt.subplots_adjust(right=0.8)
ax.plot(ztest,corr_val,'b')
ax.axvline(redshift_est,color='k',ls='--')
ax.fill_between(self.ztest,np.zeros(self.ztest.size),self.corr_prior,facecolor='grey',alpha=0.6)
ax.set_xlabel('Redshift')
ax.set_ylabel('Correlation')
self.pspec, = ax2.plot(wave,flux_sc)
ax2.axvline(3725.0*(1+redshift_est),ls='--',alpha=0.7,c='blue')
ax2.axvline(3968.5*(1+redshift_est),ls='--',alpha=0.7,c='red')
ax2.axvline(3933.7*(1+redshift_est),ls='--',alpha=0.7,c='red')
ax2.axvline(4102.9*(1+redshift_est),ls='--',alpha=0.7,c='orange')
ax2.axvline(4304.0*(1+redshift_est),ls='--',alpha=0.7,c='orange')
ax2.axvline(4862.0*(1+redshift_est),ls='--',alpha=0.7,c='orange')
ax2.axvline(4959.0*(1+redshift_est),ls='--',alpha=0.7,c='blue')
ax2.axvline(5007.0*(1+redshift_est),ls='--',alpha=0.7,c='blue')
ax2.axvline(5175.0*(1+redshift_est),ls='--',alpha=0.7,c='orange')
if self.first_pass:
self.line_est = Estimateline(self.pspec,ax2,self.uline_n)
rax = plt.axes([0.85, 0.5, 0.1, 0.2])
if self.qualityval == 0:
radio = RadioButtons(rax, ('Unclear', 'Clear'))
else:
radio = RadioButtons(rax, ('Unclear', 'Clear'),active=1)
def qualfunc(label):
if label == 'Clear':
self.qualityval = 1
else:
self.qualityval = 0
radio.on_clicked(qualfunc)
closeax = plt.axes([0.83, 0.3, 0.15, 0.1])
button = Button(closeax, 'Accept & Close', hovercolor='0.975')
def closeplot(event):
plt.close()
button.on_clicked(closeplot)
ax2.set_xlim(self.lower_w,self.upper_w)
ax2.set_xlabel('Wavelength (A)')
ax2.set_ylabel('Counts')
if not self.first_pass:
self.spectra2 = DragSpectra(self.pspec,flux_sc,ax2,self.fig)
self.fig.canvas.mpl_connect('motion_notify_event',self.spectra2.on_motion)
self.fig.canvas.mpl_connect('button_press_event',self.spectra2.on_press)
self.fig.canvas.mpl_connect('button_release_event',self.spectra2.on_release)
plt.show()
示例8: _create_plot_controls
def _create_plot_controls(self):
self._dbrax = plt.axes([0.12, 0.05, 0.15, 0.15])
self._dbradio = RadioButtons(self._dbrax, ('Amplitude', 'Phase'))
self._dbradio.on_clicked(self.set_plot_style)
self._rax = plt.axes([0.30, 0.03, 0.15, 0.20])
self._radio = RadioButtons(self._rax, ('feedback', 'feedforward', 'allpass'))
self._radio.on_clicked(self.set_comb_type)
self._sfax = plt.axes([0.6, 0.19, 0.2, 0.03])
self._dlyslider = Slider(self._sfax, 'delay (ms)', 0, (self._size/2.0) * 1000.0 / self._fs, valinit = self._delay)
self._dlyslider.on_changed(self.set_comb_delay)
self._sfax = plt.axes([0.6, 0.10, 0.2, 0.03])
self._gainslider = Slider(self._sfax, 'gain', -1, 1, valinit = self._gain)
self._gainslider.on_changed(self.set_comb_gain)
示例9: ReadFluxLC
def ReadFluxLC(self,fluxLC):
self.fluxes = fluxLC.fluxes
self.errors = array(fluxLC.fluxErrors)
self.tBins = fluxLC.tBins
self.models = fluxLC.modelNames
self.flcFlag =True
axcolor = 'lightgoldenrodyellow'
# self.radioFig = plt.figure(2)
#
ax = plt.axes([.01, 0.7, 0.2, 0.32], axisbg=axcolor)
self.data = self.fluxes['total']
if self.radio:
del self.radio
self.radioAx.cla()
self.radio = RadioButtons(self.radioAx,tuple(self.fluxes.keys()))
self.radio.on_clicked(self.Selector)
self.PlotData()
示例10: __init__
def __init__(self, image, low, high):
self.image_name = image
self.low = low
self.high = high
self.filter = None
self.output = None
self.filter_type = None
self.padRows = None
self.padCols = None
original_input = cv2.imread(image,0)
rows, cols = original_input.shape
if(rows < cols):
original_input = cv2.transpose(original_input)
self.transposed = True
else:
self.transposed = False
rows, cols = original_input.shape
optimalRows = cv2.getOptimalDFTSize(rows)
optimalCols = cv2.getOptimalDFTSize(cols)
self.padRows = optimalRows - rows
self.padCols = optimalCols - cols
self.input = np.zeros((optimalRows,optimalCols))
self.input[:rows,:cols] = original_input
self.dftshift = get_dft_shift(self.input)
plt.subplots_adjust(left=0, bottom=0.05, right=1, top=1, wspace=0, hspace=0)
plt.subplot(131)
plt.axis('off')
plt.title('original image')
plt.imshow(self.input, cmap = 'gray',interpolation='nearest')
self.axslow = plt.axes([0.05, 0.01, 0.5, 0.02])
self.slow = Slider(self.axslow, 'low', 0.01, 1, valinit=self.low)
self.slow.on_changed(self.updateLow)
self.axhigh = plt.axes([0.05, 0.03, 0.5, 0.02])
self.shigh = Slider(self.axhigh, 'high', 0.01, 1, valinit=self.high)
self.shigh.on_changed(self.updateHigh)
self.slow.slidermax=self.shigh
self.shigh.slidermin=self.slow
self.axfilter = plt.axes([0.62, 0.01, 0.15, 0.04])
self.rfilter = RadioButtons(self.axfilter, ('Gaussian Filter', 'Ideal Filter'))
self.rfilter.on_clicked(self.updateFilterType)
self.filter_type = self.rfilter.value_selected
self.axprocess = plt.axes([0.8, 0.01, 0.08, 0.04])
self.bprocess = Button(self.axprocess, 'Process')
self.bprocess.on_clicked(self.process)
self.axsave = plt.axes([0.88, 0.01, 0.08, 0.04])
self.bsave = Button(self.axsave, 'Save')
self.bsave.on_clicked(self.save)
示例11: LoadEFlux
def LoadEFlux(self,fileName):
flux = pickle.load(open(fileName))
self.fluxes = flux['energy fluxes']
self.fluxErrors = flux['errors']
self.tBins = flux['tBins']
axcolor = 'lightgoldenrodyellow'
# self.radioFig = plt.figure(2)
if self.radio:
#del self.radio
self.radioAx.cla()
#
self.radioAx = plt.axes([.01, 0.7, 0.2, 0.32], axisbg=axcolor)
self.data = self.fluxes['total']
self.errors = self.fluxErrors['total']
self.radio = RadioButtons(self.radioAx,tuple(self.fluxes.keys()))
self.radio.on_clicked(self.Selector)
self.PlotData()
示例12: __init__
def __init__(self,image=None,imginfo={},verbosity=0,cmap=None,**kwargs):
"""
image ... (opt) 2D Array
imginfo... (opt) dictionary with parameters of the image
verbosity. (opt) quiet (0), verbose (3), debug (4)
futher options are passed to the imshow method of matplotlib
"""
self.kwargs = kwargs;
self.verbosity=verbosity;
# open new figure and draw image
self.fig = plt.figure();
self.axis = self.fig.add_subplot(111);
self.fig.subplots_adjust(right=0.85);
self.AxesImage=None;
# add Switches and Buttons
axStyle = self.fig.add_axes([0.85, 0.1, 0.12, 0.12]);
self.rbStyle = RadioButtons(axStyle,["linear","log","contour"]);
self.rbStyle.on_clicked(self.set_style);
self.currentstyle = "linear";
axLine = self.fig.add_axes([0.85, 0.3, 0.12, 0.05]);
self.bLine = Button(axLine,'Line Profile');
self.bLine.on_clicked(self._toggle_line_profile);
self.LineProfile=None;
self.bLine.color_activated='red';
# key pressed
self.fig.canvas.mpl_connect('key_press_event', self._key_press_callback)
# draw image if given
self.set_cmap(cmap);
if image is not None:
self.set_image(image,imginfo);
示例13: slider_radio
def slider_radio():
def update(val):
amp = samp.val
freq = sfreq.val
l.set_ydata(amp*np.sin(2*np.pi*freq*t))
fig.canvas.draw_idle()
def reset(event):
sfreq.reset()
samp.reset()
def colorfunc(label):
l.set_color(label)
fig.canvas.draw_idle()
fig = figure()
ax = fig.subplots()
fig.subplots_adjust(left=0.25, bottom=0.25)
t = np.arange(0.0, 1.0, 0.001)
a0 = 5
f0 = 3
s = a0*np.sin(2*np.pi*f0*t)
l, = ax.plot(t, s, lw=2, color='red')
ax.axis([0, 1, -10, 10])
# %% plot axes
axcolor = 'lightgoldenrodyellow'
axfreq = fig.add_axes([0.25, 0.1, 0.65, 0.03], facecolor=axcolor)
axamp = fig.add_axes([0.25, 0.15, 0.65, 0.03], facecolor=axcolor)
# %% freq slide
sfreq = Slider(axfreq, 'Freq', 0.1, 30.0, valinit=f0)
samp = Slider(axamp, 'Amp', 0.1, 10.0, valinit=a0)
sfreq.on_changed(update)
samp.on_changed(update)
# %% reset button
resetax = fig.add_axes([0.8, 0.025, 0.1, 0.04])
button = Button(resetax, 'Reset', color=axcolor, hovercolor='0.975')
button.on_clicked(reset)
# %% color buttons
rax = fig.add_axes([0.025, 0.5, 0.15, 0.15], facecolor=axcolor)
radio = RadioButtons(rax, ('red', 'blue', 'green'), active=0)
radio.on_clicked(colorfunc)
# %% scoping
axw = [axfreq, axamp, sfreq, samp, button, radio] # place to hold all the axesWidgets to keep in scope
return axw # MUST return ax or GUI will be non-responsive!
示例14: plot_mapqs
def plot_mapqs(folder):
"""Plots the Distribution of MAPQ Scores for the Inversion Regions in the respective species
folder : input folder to look for the files
"""
mapqs_counts = defaultdict(list)
mapqs_labels = defaultdict(list)
strain_matcher = re.compile('(.*) \(.*\)') ## regex to get strain name from radio button click
## Parse the information from the mapq count files and store the information in a dictionary of lists
for mapq_file in glob.glob(folder+"*.count.txt"):
strain = mapq_file.split("/")[-1].split(".")[0]
TEMP_HANDLE = open(mapq_file,'r')
for line in TEMP_HANDLE:
line = line.strip('\n')
mapqs_counts[strain].append(int(line.split(' ')[0]))
mapqs_labels[strain].append(line.split(' ')[1])
fig, ax = plt.subplots()
indexes = np.arange(len(mapqs_counts[S]))
rects = plt.bar(indexes,mapqs_counts[S],0.5)
ax.set_xticks(indexes+1*0.2)
ax.set_xticklabels(mapqs_labels[S],rotation=30)
rax1 = plt.axes([0.92, 0.1, 0.08, 0.8])
radio1 = RadioButtons(rax1, ('MC (Sand)','CL (Sand)','CM (Sand)','CN (Sand)','TI (Sand)','DC (Sand)','MS (Sand)','CV (Sand)','PN (Rock)','AC (Rock)','LF (Rock)','MP (Rock)','MZ (Rock)'), active=0)
def update1(strain):
match = re.match(strain_matcher,strain)
strain = match.group(1)
#indexes = np.arange(len(mapqs_counts[S]))
for rect,h in zip(rects,mapqs_counts[strain]):
rect.set_height(h)
ax.set_xticks(indexes+1*0.2)
ax.set_xticklabels(mapqs_labels[strain],rotation=30)
ax.relim()
ax.autoscale()
fig.canvas.draw_idle()
#global S
#print S
#S = strain
radio1.on_clicked(update1)
plt.show()
示例15: _init_radio
def _init_radio(self):
"""
Add radio buttons to the radio ax for color scale.
self._make_radio_axes() needs to have been called.
"""
self.radio = RadioButtons(
self.radio_ax,
labels=['log', 'linear'],
active=1)