本文整理汇总了Python中matplotlib.widgets.RadioButtons.on_clicked方法的典型用法代码示例。如果您正苦于以下问题:Python RadioButtons.on_clicked方法的具体用法?Python RadioButtons.on_clicked怎么用?Python RadioButtons.on_clicked使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.widgets.RadioButtons
的用法示例。
在下文中一共展示了RadioButtons.on_clicked方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_plot
# 需要导入模块: from matplotlib.widgets import RadioButtons [as 别名]
# 或者: from matplotlib.widgets.RadioButtons 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
示例2: slide_ddg
# 需要导入模块: from matplotlib.widgets import RadioButtons [as 别名]
# 或者: from matplotlib.widgets.RadioButtons import on_clicked [as 别名]
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: WidgetsBasic
# 需要导入模块: from matplotlib.widgets import RadioButtons [as 别名]
# 或者: from matplotlib.widgets.RadioButtons import on_clicked [as 别名]
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()
示例4: run_main
# 需要导入模块: from matplotlib.widgets import RadioButtons [as 别名]
# 或者: from matplotlib.widgets.RadioButtons import on_clicked [as 别名]
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()
示例5: _GUI_display
# 需要导入模块: from matplotlib.widgets import RadioButtons [as 别名]
# 或者: from matplotlib.widgets.RadioButtons import on_clicked [as 别名]
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()
示例6: slider_radio
# 需要导入模块: from matplotlib.widgets import RadioButtons [as 别名]
# 或者: from matplotlib.widgets.RadioButtons import on_clicked [as 别名]
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!
示例7: plot_mapqs
# 需要导入模块: from matplotlib.widgets import RadioButtons [as 别名]
# 或者: from matplotlib.widgets.RadioButtons import on_clicked [as 别名]
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()
示例8: AnalyzeFrame
# 需要导入模块: from matplotlib.widgets import RadioButtons [as 别名]
# 或者: from matplotlib.widgets.RadioButtons import on_clicked [as 别名]
class AnalyzeFrame(object):
"""
A slider representing a floating point range
"""
def __init__(self, fname, n=10, intraday=False):
""" """
self.fig = plt.figure(facecolor='white')
self.fig.canvas.set_window_title(u'期货数据分析')
self.nbar = n
self.cursors = []
self.data, = load_datas(n, intraday, fname)
self.axes = []
self.rax = plt.axes([0, 0.5, 0.08, 0.15])
self.radio = RadioButtons(self.rax, ('scatter', 'summary', 'summary2', 'entry', 'exit', 'simple'), active=0)
self.axes, self.cursors = scatter_analyze(self.fig, self.data)
self.radio.on_clicked(self.update)
def update(self, op):
for ax in self.axes:
self.fig.delaxes(ax)
for c in self.cursors:
del c
if op == "scatter":
print "scatter_analyze"
self.axes, self.cursors = scatter_analyze(self.fig, self.data)
elif op == "summary":
print "summary_analyze"
self.axes, self.cursors = summary_analyze(self.fig, self.data, self.nbar, 1)
elif op == "summary2":
print "summary2_analyze"
self.axes, self.cursors = summary_analyze(self.fig, self.data, self.nbar, 2)
elif op == "entry":
print "entry_analyze"
self.axes, self.cursors = entry_analyze(self.fig, self.data, self.nbar)
elif op == "exit":
print "exit_analyze"
self.axes, self.cursors = exit_analyze(self.fig, self.data, self.nbar)
elif op == "simple":
self.axes, self.cursors = simple_entry_analyze(self.fig, self.data, self.nbar)
#elif op == "hm":
#axes, cursors = follow_entry_analyze(fig, data)
#print "hm"
self.fig.canvas.draw()
示例9: Slider
# 需要导入模块: from matplotlib.widgets import RadioButtons [as 别名]
# 或者: from matplotlib.widgets.RadioButtons import on_clicked [as 别名]
def Slider():
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider, Button, RadioButtons
fig, ax = plt.subplots()
plt.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, = plt.plot(t,s, lw=2, color='red')
plt.axis([0, 1, -10, 10])
axcolor = 'lightgoldenrodyellow'
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)
sfreq = Slider(axfreq, 'Freq', 0.1, 30.0, valinit=f0)
samp = Slider(axamp, 'Amp', 0.1, 10.0, valinit=a0)
def update(val):
amp = samp.val
freq = sfreq.val
l.set_ydata(amp*np.sin(2*np.pi*freq*t))
fig.canvas.draw_idle()
sfreq.on_changed(update)
samp.on_changed(update)
resetax = plt.axes([0.8, 0.025, 0.1, 0.04])
button = Button(resetax, 'Reset', color=axcolor, hovercolor='0.975')
def reset(event):
sfreq.reset()
samp.reset()
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)
def colorfunc(label):
l.set_color(label)
fig.canvas.draw_idle()
radio.on_clicked(colorfunc)
plt.show()
示例10: plot
# 需要导入模块: from matplotlib.widgets import RadioButtons [as 别名]
# 或者: from matplotlib.widgets.RadioButtons import on_clicked [as 别名]
def plot(Z):
ax = plt.subplot(111)
plt.subplots_adjust(bottom=0.25)
ax.contour(flatperm2.pd(Z, 1, 1).T)
ax1 = plt.axes([0.125, 0.15, 0.775, 0.03])
ax2 = plt.axes([0.125, 0.05, 0.775, 0.03])
s1 = Slider(ax1, r'$\omega_1$', 0.1, 30.0, valinit=1)
s2 = Slider(ax2, r'$\omega_2$', 0.1, 10.0, valinit=1)
plt.show()
def update(val):
w1 = s1.val
w2 = s2.val
print((w1, w2))
ax.clear()
ax.contour(flatperm2.pd(Z, w1, w2).T)
# l.set_ydata(amp*sin(2*pi*freq*t))
plt.draw()
s1.on_changed(update)
s2.on_changed(update)
return
resetax = axes([0.8, 0.025, 0.1, 0.04])
button = Button(resetax, 'Reset', color=axcolor, hovercolor='0.975')
def reset(event):
sfreq.reset()
samp.reset()
button.on_clicked(reset)
rax = axes([0.025, 0.5, 0.15, 0.15], axisbg=axcolor)
radio = RadioButtons(rax, ('red', 'blue', 'green'), active=0)
def colorfunc(label):
l.set_color(label)
draw()
radio.on_clicked(colorfunc)
show()
示例11: make_buttons
# 需要导入模块: from matplotlib.widgets import RadioButtons [as 别名]
# 或者: from matplotlib.widgets.RadioButtons import on_clicked [as 别名]
def make_buttons(self):
axcolor = 'lightgoldenrodyellow'
rax = plt.axes([0.05, 0.05, 0.15, 0.15], axisbg=axcolor)
radio = RadioButtons(rax, ('x1', 'x5', 'x10'))
radio.on_clicked(self.set_multiplier)
axprev = plt.axes([0.7, 0.05, 0.1, 0.075])
axnext = plt.axes([0.81, 0.05, 0.1, 0.075])
axup = plt.axes([0.59, 0.05, 0.1, 0.075])
axdown = plt.axes([0.48, 0.05, 0.1, 0.075])
axdone = plt.axes([0.30, 0.05, 0.1, 0.075])
bnext = Button(axnext, 'Right')
bnext.on_clicked(self.next)
bprev = Button(axprev, 'Left')
bprev.on_clicked(self.prev)
bup = Button(axup, 'Up')
bup.on_clicked(self.up)
bdown = Button(axdown, 'Down')
bdown.on_clicked(self.down)
bdone = Button(axdone, 'Done')
bdone.on_clicked(self.done)
示例12: setup_canvas
# 需要导入模块: from matplotlib.widgets import RadioButtons [as 别名]
# 或者: from matplotlib.widgets.RadioButtons import on_clicked [as 别名]
def setup_canvas(self):
"""Create the figure and the axes for the plot and buttons."""
# Initialise the figure.
self.currentFigure = plt.figure()
self.axes = self.currentFigure.add_subplot(1, 1, 1)
# Create the image.
self.start_plotting(self.originalDataset)
# Create the class radio button.
classAxesLoc = plt.axes([0.05, 0.05, 0.07, 0.1 * round(len(self.classToColorMapping) / 3)], axisbg='0.85')
classAxesLoc.set_title('Class Options')
classRadio = RadioButtons(classAxesLoc, active=0, activecolor='black', labels=[i for i in sorted(self.classToColorMapping)])
classRadio.on_clicked(self.on_class_change)
# Create the reset button.
resetAxesLoc = plt.axes([0.05, 0.44, 0.07, 0.075], axisbg='white')
resetButton = Button(resetAxesLoc, 'Reset')
resetButton.on_clicked(self.on_reset)
# Create the recompute boundaries button.
recomputeAxesLoc = plt.axes([0.05, 0.54, 0.07, 0.075], axisbg='white')
recomputeButton = Button(recomputeAxesLoc, 'Recompute')
recomputeButton.on_clicked(self.on_recompute)
# Create the k choice button.
kAxesLoc = plt.axes([0.05, 0.65, 0.07, 0.15], axisbg='0.85')
kAxesLoc.set_title('K Options')
kRadio = RadioButtons(kAxesLoc, active=0, activecolor='black', labels=[1, 3, 5, 7])
kRadio.on_clicked(self.on_k_change)
# Create the add/delete radio button.
addDeleteAxesLoc = plt.axes([0.05, 0.85, 0.07, 0.1], axisbg='0.85')
addDeleteAxesLoc.set_title('Add/Delete Points')
addDeleteRadio = RadioButtons(addDeleteAxesLoc, active=1, activecolor='black', labels=['Add', 'Delete'])
addDeleteRadio.on_clicked(self.on_delete_change)
# Attach the mouse click event.
cid = self.currentFigure.canvas.mpl_connect('button_press_event', self.on_click)
# Display the figure maximised. These commands to maximise the figure are for the Qt4Agg backend. If a different backend is being used, then
# the maximisation command will likely need to be changed.
figManager = plt.get_current_fig_manager()
figManager.window.showMaximized()
plt.show()
# Disconnect the mouse click event.
self.currentFigure.canvas.mpl_disconnect(cid)
示例13: drawffnet
# 需要导入模块: from matplotlib.widgets import RadioButtons [as 别名]
# 或者: from matplotlib.widgets.RadioButtons import on_clicked [as 别名]
def drawffnet(net, biases = False):
"""
Takes a ffnet class instance and draws the network.
Networkx layouts and maplotlib buttons are used to control layout.
Note:
This is very draft solution and it may not work for you.
"""
#Takes copies of network graphs
G = net.graph.copy()
if not biases:
try: G.delete_node(0)
except: G.remove_node(0)
BG = net.bgraph.copy()
ax = subplot(111)
subplots_adjust(left=0.25)
setp(ax, xticks=[], yticks=[])
try:
layout = NX.graphviz_layout(G, prog='dot')
active = 0
except:
layout = NX.circular_layout(G)
active = 5
NX.draw_networkx(G, layout)
# Make radio buttons for layouts
axcolor = 'lightgoldenrodyellow'
rax = axes([0.025, 0.4, 0.18, 0.35], axisbg=axcolor)
setp(rax, xticks=[], yticks=[])
text(0., 1., "Network layouts")
radio_layout = RadioButtons(rax, \
('dot', 'neato', 'fdp', 'twopi', 'circo', \
'circular', 'random', 'spring', 'shell'), \
active=active)
radio_layout.layout = layout
def layoutfunc(label):
ax.clear()
setp(ax, xticks=[], yticks=[])
try:
if label == 'dot': layout = NX.graphviz_layout(G, prog='dot')
if label == 'neato': layout = NX.graphviz_layout(G, prog='neato')
if label == 'fdp': layout = NX.graphviz_layout(G, prog='fdp')
if label == 'twopi': layout = NX.graphviz_layout(G, prog='twopi')
if label == 'circo': layout = NX.graphviz_layout(G, prog='circo')
if label == 'circular': layout = NX.circular_layout(G)
if label == 'random': layout = NX.random_layout(G)
if label == 'spring': layout = NX.spring_layout(G, iterations=15)
# if label == 'spectral': layout = NX.spectral_layout(G, iterations=50)
if label == 'shell': layout = NX.shell_layout(G)
radio_layout.layout = layout
NX.draw_networkx(G, layout)
draw()
except:
setp(ax, xlim = (0,1), ylim = (0,1))
text(0.5, 0.5, "Layout is not avilable.\n(Not working graphviz?) \n (Not installed pygraphviz?)", \
fontsize=14, color='r', horizontalalignment='center')
radio_layout.on_clicked(layoutfunc)
# Make a button for showing adjoint network (backpropagation network)
bgraphax = axes([0.025, 0.3, 0.18, 0.04])
button1 = Button(bgraphax, 'Backprop graph', color=axcolor, hovercolor='0.975')
def showbgraph(event):
ax.clear()
setp(ax, xticks=[], yticks=[])
layout = radio_layout.layout
NX.draw_networkx(G, layout, alpha=0.1, labels={})
NX.draw_networkx(BG, layout, node_color='y')
draw()
button1.on_clicked(showbgraph)
# Make a button for showing derivative networks
dgraphax = axes([0.025, 0.2, 0.18, 0.04])
button2 = Button(dgraphax, 'Diff graphs', color=axcolor, hovercolor='0.975')
def showdgraphs(event):
def dsubgraph_nodes(inp, out, nbunch):
pred = NX.predecessor(G, inp, out)
nbunch += pred
for node in pred:
dsubgraph_nodes(inp, node, nbunch)
return nbunch
layout = radio_layout.layout
import time
for innode in net.inno:
for outnode in net.outno:
nbunch = [outnode]
nbunch = dsubgraph_nodes(innode, outnode, nbunch)
g = G.subgraph(nbunch)
ax.clear()
setp(ax, xticks=[], yticks=[])
NX.draw_networkx(G, layout, alpha=0.1, labels={})
NX.draw_networkx(g, layout, node_color='c')
draw()
time.sleep(3)
button2.on_clicked(showdgraphs)
#.........这里部分代码省略.........
示例14: __init__
# 需要导入模块: from matplotlib.widgets import RadioButtons [as 别名]
# 或者: from matplotlib.widgets.RadioButtons import on_clicked [as 别名]
class ParametricEQSelector:
def __init__(self):
self._fs = 48000
self._nbands = 7
self._params = []
for i in range(0, self._nbands):
self._params.append({'center': 0, 'resonance': 1.0/math.sqrt(2.0), 'dbgain': 0})
self._selected_band = 0
self._blocksize = 512
self._nfft = int(self._blocksize / 2)
self._impulse_response = [0] * self._blocksize
self._freq_response_real = [0] * self._blocksize
self._freq_response_imag = [0] * self._blocksize
self._response = [0] * self._blocksize
self._plot_db = True
self._eq = yodel.filter.ParametricEQ(self._fs, self._nbands)
self._create_plot()
self._create_plot_controls()
self.select_band('Band ' + str(self._selected_band+1))
def _create_plot(self):
self._fig, self._ax = plt.subplots()
self._ax.set_title('Parametric Equalizer Design')
self._ax.grid()
plt.subplots_adjust(bottom=0.3)
self._update_filter_response()
self._x_axis = [i*(self._fs/2/self._nfft) for i in range(0, self._nfft)]
self._y_axis = self._response[0:self._nfft]
self._l_center, = self._ax.plot(self._x_axis, [0] * self._nfft, 'k')
self._l_fr, = self._ax.plot(self._x_axis, self._y_axis, 'b')
self._rescale_plot()
def _create_plot_controls(self):
self._dbrax = plt.axes([0.12, 0.05, 0.13, 0.10])
self._dbradio = RadioButtons(self._dbrax, ('Amplitude', 'Phase'))
self._dbradio.on_clicked(self.set_plot_style)
self._rax = plt.axes([0.27, 0.03, 0.15, 0.20])
bands_list = []
for i in range(1, self._nbands+1):
bands_list.append('Band ' + str(i))
self._radio = RadioButtons(self._rax, tuple(bands_list))
self._radio.on_clicked(self.select_band)
self._sfax = plt.axes([0.6, 0.19, 0.2, 0.03])
self._sqax = plt.axes([0.6, 0.12, 0.2, 0.03])
self._sdbax = plt.axes([0.6, 0.05, 0.2, 0.03])
self._fcslider = Slider(self._sfax, 'Cut-off frequency', 0, self._fs/2, valinit = self._params[self._selected_band]['center'])
self._qslider = Slider(self._sqax, 'Q factor', 0.01, 10.0, valinit = self._params[self._selected_band]['resonance'])
self._dbslider = Slider(self._sdbax, 'dB gain', -20.0, 20.0, valinit = self._params[self._selected_band]['dbgain'])
self._fcslider.on_changed(self.set_center_frequency)
self._qslider.on_changed(self.set_resonance)
self._dbslider.on_changed(self.set_dbgain)
def _rescale_plot(self):
if self._plot_db:
self._ax.set_ylim(-30, 30)
else:
self._ax.set_ylim(- 200, 200)
plt.draw()
def _plot_frequency_response(self, redraw=True):
self._update_filter_response()
self._y_axis = self._response[0:self._nfft]
self._l_fr.set_ydata(self._y_axis)
if redraw:
plt.draw()
def _plot_range_limits(self, redraw=True):
self._l_center.set_ydata([0] * self._nfft)
if redraw:
plt.draw()
def set_plot_style(self, style):
if style == 'Phase':
self._plot_db = False
elif style == 'Amplitude':
self._plot_db = True
self._plot_range_limits(False)
self._plot_frequency_response(False)
self._rescale_plot()
def select_band(self, band):
idx = band.split(' ')
self._selected_band = int(idx[1]) - 1
self._fcslider.set_val(self._params[self._selected_band]['center'])
self._qslider.set_val(self._params[self._selected_band]['resonance'])
self._dbslider.set_val(self._params[self._selected_band]['dbgain'])
def set_center_frequency(self, val):
self._params[self._selected_band]['center'] = val
self._set_band(self._selected_band)
self._plot_frequency_response()
#.........这里部分代码省略.........
示例15: RadioButtons
# 需要导入模块: from matplotlib.widgets import RadioButtons [as 别名]
# 或者: from matplotlib.widgets.RadioButtons import on_clicked [as 别名]
radio = RadioButtons(rax,('Linear','Log'))
def radio_click(label):
if label== 'Linear':
plt.title( 'linear',loc = 'right')
logx ==0
logy ==0
elif label== 'Log':
plt.title( 'log',loc='right')
logx ==1
logy ==1
radio.on_clicked(radio_click)
###############################################################################
# Calculation button:
# Plots the results and prints the x and y value
################################################################################
x,y = calculation(xmin, xmax, ymin, ymax, xaxis, yaxis, logx, logy, xdata, ydata)
bax = plt.axes([0.01,0.19,0.1,0.03])
calc_button = Button(bax,'Calculate',image = None, color = '0.95',hovercolor = '0.65')
def calculate_button(event):
x,y= calculation(xmin, xmax, ymin, ymax, xaxis, yaxis, logx, logy, xdata, ydata)
print x,y
plt.figure()
plt.plot(x, y)
plt.show()