vis.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:P_MDP_TG 作者: MengGuo 项目源码 文件源码
def visualize_run(XX, LL, UU, MM, name=None):
    #-----plot the sequence of states for the test run    
    figure = plt.figure()
    ax = figure.add_subplot(1,1,1)
    N = len(XX)
    #print 'N: %s' %N
    #----
    for n in xrange(0, N):
        X = list(XX[n])
        L = list(LL[n])
        U = list(UU[n])
        M = list(MM[n])
        K = len(X)
        #print 'K: %s' %K
        RAD = 0.3
        for k in xrange(0, K):
            if M[k] == 0:
                color = 'blue'
            if M[k] == 1:
                color = 'magenta'
            if M[k] == 2:
                color = 'black'
            #----
            rec = matplotlib.patches.Rectangle((4*k-RAD, 3*n-RAD),
                                               RAD*2, RAD*2,
                                               fill = False,
                                               edgecolor = color,
                                               linewidth = 3,
                                               ls = 'solid',
                                               alpha =1)
            ax.add_patch(rec)
            setstr = r''
            for s in L[k]:
                setstr += s
                setstr +=','
            ax.text(4*k-RAD, 3*n+RAD*4, r'$(%s, \{%s\})$' %(str(X[k]), str(setstr)), fontsize = 6, fontweight = 'bold')
            #----
            if (k<= K-2):
                line = matplotlib.lines.Line2D([4*k+RAD,4*k+4-RAD],
                                               [3*n, 3*n],
                                               linestyle='-',
                                               linewidth=1,
                                               color='black')
                ax.add_line(line)
                actstr = r''
                for s in U[k]:
                    actstr += s
                ax.text(4*k+2, 3*n+RAD, r'%s' %str(actstr), fontsize = 6, fontweight = 'bold')
    ax.set_aspect(0.7)
    ax.set_xlim(-1, 4*K)
    ax.set_ylim(-1, 3*N)
    ax.set_xlabel(r'$state\; sequence$')
    ax.set_ylabel(r'$run$')    
    #ax.axis('off')
    if name:
        plt.savefig('%s.pdf' %name,bbox_inches='tight')
    return figure
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号