# If using matplotlib, we must create the canvas area of the Window before # creating the actual Sliders. if use_mpl: # Create root Tk widget and set the title root = tk.Tk() root.title(prog_title) # Create and pack the renderable area of the widget, using the figure class plot_widget = FigureCanvasTkAgg(fig, master=root) plot_widget.show() plot_widget.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=True) plot_widget._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=True) # Create the sliders for the length and reflectivity parameters. length = Slider(axes_length, "Cavity length", 0.01, 1, valinit=L) reflect = Slider(axes_reflect, "Reflectivity", 0.1, 1, valinit=R) # Create a callback function for the slider controls def update(val): # Replot the graph using the new values R = reflect.val L = length.val T = np.sqrt(1.0 - R ** 2) D = T ** 4 + 4 * R ** 2 * np.sin(2 * np.pi * (w + w_hene) / c * L) ** 2 I = T ** 4 / D plt.set_ydata(F * I * 1e6) # Render the result on the canvas fig.canvas.draw()
rugRect=[0.15, 0.20, 0.7, 0.05] #controlRect=[0.05, 0.20, 0.15, 0.25] locRect=[0.15, 0.1, 0.65, 0.03] zoomRect=[0.15, 0.05, 0.65, 0.03] fig=plt.figure(facecolor='white') axescolor="#f6f6f6" #controlPanel=fig.add_axes(controlRect) #controlFields=[] #radio=RadioButtons(controlPanel, hist.fieldnames, active=0) axloc = axes(locRect, axisbg=axescolor) axzoom = axes(zoomRect, axisbg=axescolor) initLoc=int(location) #initLoc=(hist.max-hist.min)/2+hist.min initWidth=500 sLoc = Slider(axloc, 'Location', hist.min, hist.max , valinit=initLoc) sZoom = Slider(axzoom, 'Width', 1, 1000, valinit=initWidth) #set up the axes ax1=fig.add_axes(histRect, axisbg=axescolor) ax1.grid(True) plt.title("Frequency of %s" %column) plt.ylabel('Frequency') ax1.axes.get_xaxis().set_visible(False) ax2=fig.add_axes(rugRect, axisbg=axescolor, sharex=ax1) zeros=[0]*hist.length() ax2.axes.get_yaxis().set_visible(False) plt.xlabel(column) #draw the initial histograms ax1.hist(hist.data, facecolor='green', alpha=0.75, align='mid', range=(hist.min, hist.max), rwidth=1)