我需要设置 matplotlib 小部件的高度,更改对齐方式或更改字体,但我不知道如何。
截图:
5 个单选按钮:
15 个单选按钮:
这是关键代码部分:
def evolvecallback_(self, notification):
global i
stats={}
results=[]
fitnesses=[]
for code,fit in evolve(i):
results.append(code)
stats[str(fit)]=code
fitnesses.append(str(fit))
i+=1
fig = plt.figure()
done=""
if found():
done=" - Solution found!"
print "Done!"
fig.canvas.set_window_title("Generation "+str(i)+". - Best migrating individuals"+done)
ax = plt.subplot(111)
ax.set_title(stats[str(fitnesses[0])])
l, = ax.plot(x, s0, lw=2, color='blue')
plt.subplots_adjust(left=0.4)
axcolor = 'lightgoldenrodyellow'
rax = plt.axes([0.05, 0.7, 0.15, 0.15], axisbg=axcolor)
radio = RadioButtons(rax, tuple(fitnesses))
def change(label):
hzdict = {}
x = np.arange(-5.0, 5.0, 0.01)
j=0
for i in tuple(results):
hzdict[fitnesses[j]]=eval(i)
j+=1
ax.set_title(stats[str(label)])
ydata = hzdict[str(label)]
l.set_ydata(ydata)
plt.draw()
radio.on_clicked(change)
plt.show()