%pylab qt from pylab import * from matplotlib.widgets import RadioButtons from matplotlib.patches import Circle # step 1 fig = figure(figsize=(12,8)) ax1 = fig.add_axes([0.4,0.1,0.4,0.8], aspect='equal') c1 = Circle(xy=(0,0),radius=2) ax1.add_patch(c1) ax1.set_xlim(-5,5) ax1.set_ylim(-5,5) # step 2 rax = fig.add_axes([0.1,0.45,0.2,0.2], aspect='equal', title='Radius') # step 3 radio = RadioButtons( rax, ['1','2','6'], active=1, activecolor='r') # step 4 def setradius(label): c1.set_radius(float(label)) draw() # step 5 radio.on_clicked(setradius) # step 6 show() from pylab import * from matplotlib.widgets import RadioButtons from matplotlib.lines import Line2D # Step 1: Create figure with the line fig = figure(figsize=(12,8)) ax = fig.add_axes([0.4,0.1,0.5,0.8],aspect='equal') a = 1 b = 0 x = linspace(0,20,10) y = a * x + b line1 = Line2D(x,y) ax.add_line(line1) xlim(0,20) ylim(0,20) # Radio buttons for slope ax1 = fig.add_axes([0.1,0.65,0.2,0.2], aspect='equal', title='slope') # step 2 slope = RadioButtons( ax1, ['0.5','1','2'], active=1, activecolor='r') # step 3 def setslope(label): # step 4 a = float(label) y = a * x + b line1.set_ydata(y) draw() slope.on_clicked(setslope) # step 5 show() # step 6 from pylab import * from matplotlib.widgets import RadioButtons from matplotlib.lines import Line2D # Create figure with line fig = figure(figsize=(12,8)) ax = fig.add_axes([0.4,0.1,0.5,0.8],aspect='equal') a = 1 b = 0 x = linspace(0,20,10) y = a * x + b line1 = Line2D(x,y) ax.add_line(line1) xlim(0,20) ylim(0,20) # Radio buttons for slope and intercept ax1 = fig.add_axes([0.1,0.65,0.2,0.2], aspect='equal', title='slope') # step 2 ax2 = fig.add_axes([0.1,0.25,0.2,0.2], aspect='equal') slope = RadioButtons( ax1, ['0.5','1','2'], active=1, activecolor='r') # step 3 intercept = RadioButtons( ax2, ['0','5','10'], active=0, activecolor='r') def setslope(label): # step 4 global a a = float(label) y = a * x + b line1.set_ydata(y) draw() def setintercept(label): global b b = float(label) y = a * x + b line1.set_ydata(y) draw() slope.on_clicked(setslope) # step 5 intercept.on_clicked(setintercept) show() # step 6 from pylab import * from matplotlib.widgets import Slider from matplotlib.patches import Circle # Step 1: Create figure with circle and line fig = figure(figsize=(6,8)) ax1 = fig.add_axes([0.1,0.3,0.8,0.6], aspect='equal') R = 3 c1 = Circle(xy=(0,0),radius=R,fc='violet') ax1.add_patch(c1) angle = 0 line1 = Line2D(xdata = [-R*cos(angle),R*cos(angle)],\ ydata = [-R*sin(angle),R*sin(angle)],color='k') ax1.add_line(line1) xlim(-5,5) ylim(-5,5) # Step 2: Create axis for slider axslider = fig.add_axes([0.2,0.15,0.6,0.05]) # Step 3: Create slider and add to axis angleslider = Slider(axslider, 'Angle', -180, 180, valinit=0) # Step 4: Function to call when slider is changed def setangle(val): angle = val * pi/180 line1.set_xdata([-R*cos(angle),R*cos(angle)]) line1.set_ydata([-R*sin(angle),R*sin(angle)]) draw() # Step 5: Tell the angleslider what function to call when its value has changed angleslider.on_changed(setangle) # Step 6: Call show() show() from pylab import * from matplotlib.widgets import RadioButtons from matplotlib.patches import Circle # Create figure with circle fig = figure(figsize=(12,8)) ax1 = fig.add_axes([0.4,0.1,0.5,0.8], aspect='equal') c1 = Circle(xy=(0,0),radius=2,color='blue') ax1.add_patch(c1) xlim(-5,5) ylim(-5,5) # Radio buttons for radius of circle rax = axes([0.1,0.65,0.2,0.2], aspect='equal', title='Radius') radio = RadioButtons( rax, ['1','2','6'], active=1, activecolor='r') def setradius(label): c1.set_radius(float(label)) draw() radio.on_clicked(setradius) # Radio buttons for color of circle cax = axes([0.1,0.25,0.2,0.2], aspect='equal', title='Color') color = RadioButtons( cax, ['violet','blue','green','black'], active=1, activecolor='r') def setcolor(label): c1.set_color(label) draw() color.on_clicked(setcolor) show() from pylab import * from matplotlib.widgets import RadioButtons from matplotlib.lines import Line2D fig = figure() ax1 = fig.add_axes([0.1,0.4,0.8,0.5]) E = 11e3 I = 1067e6 q = 100 L = 5000 x = linspace(0,L,100) d = -q * x / (24*E*I) * (L**3 - 2*L*x**2 + x**3) line = Line2D(xdata=x,ydata=d) ax1.add_line(line) xlabel('x (mm)') ylabel('deflection (mm)') xlim(0,L) ylim(-100,0) ax2 = fig.add_axes([0.05,0.05,0.2,0.2],aspect='equal',title='material') ax3 = fig.add_axes([0.55,0.05,0.2,0.2],aspect='equal',title='qload') Emod = RadioButtons( ax2, ['wood','concrete','aluminum'], active=0, activecolor='r') qload = RadioButtons( ax3, ['50','100','200'], active=1, activecolor='r') def setEmod(label): global E if label == 'wood': E = 11e3 if label == 'concrete': E = 35e3 if label == 'aluminum': E = 71e3 d = -q * x / (24*E*I) * (L**3 - 2*L*x**2 + x**3) line.set_ydata(d) draw() def setqload(label): global q q = float(label) d = -q * x / (24*E*I) * (L**3 - 2*L*x**2 + x**3) line.set_ydata(d) draw() Emod.on_clicked(setEmod) qload.on_clicked(setqload) show() from pylab import * from matplotlib.widgets import Slider from matplotlib.patches import Circle fig = figure(figsize=(6,8)) ax1 = fig.add_axes([0.1,0.3,0.8,0.6], aspect='equal') R = 3 c1 = Circle(xy=(0,0),radius=R,fc='violet') ax1.add_patch(c1) angle = 0 l1 = Line2D(xdata = [-R*cos(angle),R*cos(angle)],\ ydata = [-R*sin(angle),R*sin(angle)],color='k') ax1.add_line(l1) c2 = Circle(xy=(R*cos(angle),R*sin(angle)),radius=0.2,fc='b') ax1.add_patch(c2) xlim(-5,5) ylim(-5,5) axslider = fig.add_axes([0.2,0.15,0.6,0.05]) angleslider = Slider(axslider, 'Angle', -180, 180, valinit=0) axslider2 = fig.add_axes([0.2,0.05,0.6,0.05]) angleslider2 = Slider(axslider2, 'Radius', 2, 4, valinit=3) def update(val): angle = val * pi/180 R = angleslider2.val l1.set_xdata([-R*cos(angle),R*cos(angle)]) l1.set_ydata([-R*sin(angle),R*sin(angle)]) c2.center = R*cos(angle),R*sin(angle) draw() def update2(R): angle = angleslider.val * pi/180 l1.set_xdata([-R*cos(angle),R*cos(angle)]) l1.set_ydata([-R*sin(angle),R*sin(angle)]) c2.center = R*cos(angle),R*sin(angle) c1.radius = R draw() angleslider.on_changed(update) angleslider2.on_changed(update2) show()