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


Python RadioButtons.layout方法代码示例

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


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

示例1: drawffnet

# 需要导入模块: from matplotlib.widgets import RadioButtons [as 别名]
# 或者: from matplotlib.widgets.RadioButtons import layout [as 别名]
def drawffnet(net, biases = False):
    """
    Takes a ffnet class instance and draws the network. 
    Networkx layouts and maplotlib buttons are used to control layout. 
    
    Note:
    This is very draft solution and it may not work for you.
    """
    
    #Takes copies of network graphs
    G = net.graph.copy()
    if not biases: 
        try: G.delete_node(0)
        except: G.remove_node(0)
    BG = net.bgraph.copy()
    
    
    ax = subplot(111)
    subplots_adjust(left=0.25)
    setp(ax, xticks=[], yticks=[])
    try:
        layout = NX.graphviz_layout(G, prog='dot')
        active = 0
    except:
        layout = NX.circular_layout(G)
        active = 5
    NX.draw_networkx(G, layout)
    
    # Make radio buttons for layouts
    axcolor = 'lightgoldenrodyellow'
    
    rax = axes([0.025, 0.4, 0.18, 0.35], axisbg=axcolor)
    setp(rax, xticks=[], yticks=[])
    
    text(0., 1., "Network layouts")
    radio_layout = RadioButtons(rax, \
                    ('dot', 'neato', 'fdp', 'twopi', 'circo', \
                    'circular', 'random', 'spring', 'shell'), \
                    active=active)
    radio_layout.layout = layout
    def layoutfunc(label):
        ax.clear()
        setp(ax, xticks=[], yticks=[])
        try:
            if label == 'dot': layout = NX.graphviz_layout(G, prog='dot')
            if label == 'neato': layout = NX.graphviz_layout(G, prog='neato')
            if label == 'fdp': layout = NX.graphviz_layout(G, prog='fdp')
            if label == 'twopi': layout = NX.graphviz_layout(G, prog='twopi')
            if label == 'circo': layout = NX.graphviz_layout(G, prog='circo')
            if label == 'circular': layout = NX.circular_layout(G)
            if label == 'random': layout = NX.random_layout(G)
            if label == 'spring': layout = NX.spring_layout(G, iterations=15)
            # if label == 'spectral': layout = NX.spectral_layout(G, iterations=50)
            if label == 'shell': layout = NX.shell_layout(G)
    
            radio_layout.layout = layout
            NX.draw_networkx(G, layout)
            draw()
        except:
            setp(ax, xlim = (0,1), ylim = (0,1))
            text(0.5, 0.5, "Layout is not avilable.\n(Not working graphviz?) \n (Not installed pygraphviz?)", \
                fontsize=14, color='r', horizontalalignment='center')
    radio_layout.on_clicked(layoutfunc)
    
    # Make a button for showing adjoint network (backpropagation network)
    bgraphax = axes([0.025, 0.3, 0.18, 0.04])
    button1 = Button(bgraphax, 'Backprop graph', color=axcolor, hovercolor='0.975')
    def showbgraph(event):
        ax.clear()
        setp(ax, xticks=[], yticks=[])
        layout = radio_layout.layout
        NX.draw_networkx(G, layout, alpha=0.1, labels={})
        NX.draw_networkx(BG, layout, node_color='y')
        draw()
    button1.on_clicked(showbgraph)
    
    # Make a button for showing derivative networks
    dgraphax = axes([0.025, 0.2, 0.18, 0.04])
    button2 = Button(dgraphax, 'Diff graphs', color=axcolor, hovercolor='0.975')
    def showdgraphs(event):
        def dsubgraph_nodes(inp, out, nbunch):
            pred = NX.predecessor(G, inp, out)
            nbunch += pred
            for node in pred:
                dsubgraph_nodes(inp, node, nbunch)
            return nbunch
        layout = radio_layout.layout
        import time
        for innode in net.inno:
            for outnode in net.outno:               
                nbunch = [outnode]
                nbunch = dsubgraph_nodes(innode, outnode, nbunch)
                g = G.subgraph(nbunch)
                ax.clear()
                setp(ax, xticks=[], yticks=[])
                NX.draw_networkx(G, layout, alpha=0.1, labels={})
                NX.draw_networkx(g, layout, node_color='c')
                draw()
                time.sleep(3)
    button2.on_clicked(showdgraphs)
#.........这里部分代码省略.........
开发者ID:pombreda,项目名称:aichallenge-1,代码行数:103,代码来源:drawffnet.py


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