python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -
i new programming please pardon me if rookie mistake.
i writing python script have defined functions create subplots of distributions.
i have slider widget end user change value of variables(mu , sigma) , see effect on distribution. here's code
import numpy np print np.__version__ import scipy print scipy.__version__ scipy.stats import norm, lognorm, uniform import matplotlib print matplotlib.__version__ import matplotlib.pyplot plt matplotlib.widgets import slider, button, radiobuttons, checkbuttons #####calculating mean , standard deviation##### global mu_a1 mu_a1 = 1 global mu_b1 mu_b1 = 10 global mu_c1 mu_c1 = -13 global sigma_a1 sigma_a1 = 0.14 global sigma_b1 sigma_b1 = 1.16 global sigma_c1 sigma_c1 = 2.87 mu_x01 = -11 sigma_x01 = 1.9 #####_____##### #####generating random data##### a1 = 0.75*mu_a1 + (1.25 - 0.75)*sigma_a1*np.random.sample(10000) b1 = 8*mu_b1 + (12 - 8)*sigma_b1*np.random.sample(10000) c1 = -12*mu_c1 + 2*sigma_c1*np.random.sample(10000) x01 = (-b1 - np.sqrt(b1**2 - (4*a1*c1)))/(2*a1) #####_____##### #######creating subplots & plotting distributions##### fig = plt.figure() plt.subplots_adjust(left=0.13,right=0.99,bottom=0.05) def ax1(): ax1 = fig.add_subplot(331) ax1.clear() ax1.set_xlabel('a' , fontsize = 14) ax1.grid(true) [n1,bins1,patches] = ax1.hist(a1, bins=50, color = 'red',alpha = 0.5, normed = true) return ax1 def ax2(): ax2 = fig.add_subplot(334) ax2.clear() ax2.set_xlabel('b' , fontsize = 14) ax2.grid(true) [n2,bins2,patches] = ax2.hist(b1, bins=50, color = 'red',alpha = 0.5, normed = true) return ax2 def ax3(): ax3 = fig.add_subplot(337) ax3.clear() ax3.set_xlabel('c' , fontsize = 14) ax3.grid(true) [n3,bins3,patches] = ax3.hist(c1, bins=50, color = 'red',alpha = 0.5, normed = true) return ax3 def ax4_ax5(): ax4 = fig.add_subplot(132) ax4.clear() ax4.set_xlabel('x0' , fontsize = 14) ax4.grid(true) [n4,bins4,patches] = ax4.hist(x01, bins=50, color = 'red',alpha = 0.5, normed = true) ax4.axvline(np.mean(x01), color = 'black', linestyle = 'dashed', lw = 2) ax5 = fig.add_subplot(133) ax5.clear() ax5.set_xlabel('x0' , fontsize = 14) ax5.set_ylabel('cdf', fontsize = 14) ax5.grid(true) dx = bins4[1] - bins4[0] cdf = np.cumsum(n4)*dx ax5.plot(bins4[1:], cdf, color = 'red') return ax4,ax5 #######_____##### ax1 = ax1() ax2 = ax2() ax3 = ax3() ax4, ax5 = ax4_ax5() #####creating sliders##### axcolor = 'lightgoldenrodyellow' axmu_331 = plt.axes([0.015, 0.67, 0.07, 0.015], axisbg=axcolor) axsigma_331 = plt.axes([0.015, 0.65, 0.07, 0.015], axisbg=axcolor) smu_331 = slider(axmu_331, 'm', -13.0 , 10.0, valinit = 1.0) ssigma_331 = slider(axsigma_331, 'sd', -3.0 , 3.0, valinit =1.0) #####_____##### #####updating sliders##### def update_slider_331(val): mu_a1 = smu_331.val print mu_a1 sigma_a1 = ssigma_331.val print sigma_a1 ax1() ax4_ax5() plt.draw() smu_331.on_changed(update_slider_331) ssigma_331.on_changed(update_slider_331) #####_____##### plt.show()
i distribution update every time slider value changed . however, when change slider value, error
traceback (most recent call last): file "c:\program files (x86)\python27\lib\site-packages\matplotlib\backends\backend_qt4.py", line 175, in mousepressevent figurecanvasbase.button_press_event( self, x, y, button ) file "c:\program files (x86)\python27\lib\site-packages\matplotlib\backend_bases.py", line 1632, in button_press_event self.callbacks.process(s, mouseevent) file "c:\program files (x86)\python27\lib\site-packages\matplotlib\cbook.py", line 262, in process proxy(*args, **kwargs) file "c:\program files (x86)\python27\lib\site-packages\matplotlib\cbook.py", line 192, in __call__ return mtd(*args, **kwargs) file "c:\program files (x86)\python27\lib\site-packages\matplotlib\widgets.py", line 315, in _update self.set_val(val) file "c:\program files (x86)\python27\lib\site-packages\matplotlib\widgets.py", line 327, in set_val func(val) file "h:/uq&m/gui demos/wip/stack overflow_func.py", line 118, in update_slider_331 ax1() typeerror: 'axessubplot' object not callable
i have mouse click event (not shown in above code) call 'ax' functions , work fine. wondering why not working slider update function.
thanks in advance :-)
Comments
Post a Comment