当前位置: 首页>>代码示例>>Python>>正文


Python RadioButtons.val方法代码示例

本文整理汇总了Python中matplotlib.widgets.RadioButtons.val方法的典型用法代码示例。如果您正苦于以下问题:Python RadioButtons.val方法的具体用法?Python RadioButtons.val怎么用?Python RadioButtons.val使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matplotlib.widgets.RadioButtons的用法示例。


在下文中一共展示了RadioButtons.val方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: plot

# 需要导入模块: from matplotlib.widgets import RadioButtons [as 别名]
# 或者: from matplotlib.widgets.RadioButtons import val [as 别名]
    def plot(self):
        print "Plotting..."

        plot_var="H_h_vi"
        t_init=0
        t=t_init
        ds=self.dm[t]
        data=ds.__dict__[plot_var][::-1]
        lenY,lenX=data.shape

        print "-----------------------------------------------------"
        print plot_var
        print data

        ax=plt.subplot(111)
        plt.subplots_adjust(left=0.30,bottom=0.25)

        xx=np.arange(lenX) + 0.3
        width = 0.35

        yoff=np.array([0.]*xx)
        colours=self.get_colours(len(xx))
        pp=[]

        for h in range(lenY):
            yy=data[h,:]
            pp.append(plt.bar(xx, yy, width,
                    color=colours[h],bottom=yoff))
            yoff = yoff+yy

        #max_y is the height of the highest stacked bar
        max_y=1.1*np.ceil(max([self.dm[ti].__dict__[plot_var][:,vi][self.dm[ti].__dict__[plot_var][:,vi]>0].sum() for vi in range(lenX) for ti in range(self.sim.params.T_MAX)]))
        min_y=1.1*np.floor(min([self.dm[ti].__dict__[plot_var][:,vi][self.dm[ti].__dict__[plot_var][:,vi]<0].sum() for vi in range(lenX) for ti in range(self.sim.params.T_MAX)]))

        plt.xticks(xx+width/2.,np.arange(lenX))
        plt.ylim(min_y,max_y)
        #plt.yticks(np.arange(0,max_y*1.1+0.5,0.5))

        plt.ylabel(plot_var)
        plt.xlabel('vi')
        plt.title('Allocated {} per location'.format(plot_var))

        plt.axhline(y=0)

        legend_labels=["h="+str(x) for x in range(lenY)]
        legend_labels[0]=legend_labels[0]+":High income"
        legend_labels[-1]=legend_labels[-1]+":Low income"
        legend_labels=tuple(legend_labels)

        leg=plt.legend( tuple([x[0] for x in pp][::-1]),
                legend_labels, loc='best',fancybox=True)
        leg.get_frame().set_alpha(0.5)

        axcolor = 'lightgoldenrodyellow'
        axtime=plt.axes([0.25,0.1,0.65,0.03],axisbg=axcolor)
        axiter=plt.axes([0.25,0.15,0.65,0.03],axisbg=axcolor)

        radio_labels=['H_h_vi', 'I_h_vi','P_h_vi','b_h_vi','B_h_vi','avgZ_vi','H_h','b_h', 'r_vi', 'S_vi']
        rax = plt.axes([0.025, 0.4, 0.17, 0.05*len(radio_labels)], axisbg=axcolor)

        plt.title(self.sim.sim_name)
        stime = Slider(axtime, 'Time', 0, self.sim.params.T_MAX-1,valfmt='%1.0f', valinit=0)

        last_iter=max([self.dm[x].iters_count for x in range(self.sim.params.T_MAX)])
        iter=last_iter
        siter = Slider(axiter, 'Iter', 0, last_iter-1,valfmt='%1.0f', valinit=iter)

        radio = RadioButtons(rax,radio_labels , active=0)
        radio.val=radio_labels[0]
        bar_labels=self.autolabel(pp,ax)


        def update(val):
            t = int(round(stime.val,0))
            iter =int(round(siter.val,0))

            if val in radio_labels:
                radio.val=val
            plot_var=radio.val

            if iter<self.dm[t].iters_count:
                ds=self.dm[t].iters[iter]
            else:
                ds=self.dm[t]

            #TO DO: Permitir variables de dimension 1
            data=ds.__dict__[plot_var]
            if data.size>1:
                data=data[::-1]
                lenY,lenX=data.shape
            else:
                lenY=1
                lenX=1

            last_iter=self.dm[t].iters_count

            max_y=1.1*np.ceil(max([self.dm[ti].__dict__[plot_var][:,vi][self.dm[ti].__dict__[plot_var][:,vi]>0].sum() for vi in range(lenX) for ti in range(self.sim.params.T_MAX)]))
            min_y=1.1*np.floor(min([self.dm[ti].__dict__[plot_var][:,vi][self.dm[ti].__dict__[plot_var][:,vi]<0].sum() for vi in range(lenX) for ti in range(self.sim.params.T_MAX)]))

            plt.ylim(min_y,max_y)
#.........这里部分代码省略.........
开发者ID:cristeprado,项目名称:qsim,代码行数:103,代码来源:plotter.py


注:本文中的matplotlib.widgets.RadioButtons.val方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。