0

この回答に触発されsegmentsて、太い黄色の半透明の線で強調しようとしていますhighlighter。の可視部分はhighlighterによって拘束されpropAreaます。

コード:

def showAfterExpand(segments, segWidths, trajectories):
    print segWidths
    fig = plt.figure()
    axes = fig.add_axes([0.1, 0.1, 0.8, 0.8]) # left, bottom, width, height (range 0 to 1)
    axes.axis('equal')
    axes.set_xlabel('x (m)')
    axes.set_ylabel('y (m)')
    axes.set_title('After Expanding')
    for i, segment in enumerate(segments):
        # draw this segment
        axes.plot([segment[0][0], segment[1][0]], [segment[0][1], segment[1][1]], color='b')
        w1, w2 = segWidths[i][0], segWidths[i][1]
        len = np.linalg.norm((segment[0][0]-segment[1][0], segment[0][1]-segment[1][1]))
        # make sure to use data 'units', so set the transform to transData
        propArea = pch.Rectangle(segment[0], width=len, height=w1 + w2, transform=axes.transData)
        # save the line so when can set the clip
        highlighter, = axes.plot([segment[0][0], segment[1][0]], [segment[0][1], segment[1][1]],
                              color='yellow', 
                              linewidth=50, 
                              alpha=0.5)
        highlighter.set_clip_path(propArea)
    fig.savefig(constants.PROJECT_PATH + '\\data\\%i_7_expand.svg'%len(trajectories))

エラーメッセージ:

in showAfterExpand(segments, segWidths, trajectories)
    163                               alpha=0.5)
    164         corridor.set_clip_path(propArea)
--> 165     fig.savefig(constants.PROJECT_PATH + '\\data\\%i_7_expand.svg'%len(trajectories))

TypeError: 'numpy.float64' object is not callable

注:問題を簡単に特定できるように、コードを「コピー アンド ペーストで実行可能」にする必要があることを十分に理解しています。私は本当に一生懸命試しましたが、奇妙なことに、それを単純化して「コピーアンドペースト実行可能」にすると、エラーはなくなりました! したがって、スニペットを直接投稿するしかありません。

何が悪かったのか?

4

1 に答える 1

2

あなたはlenこの線でシャドーイングしています

len = np.linalg.norm((segment[0][0]-segment[1][0], segment[0][1]-segment[1][1]))

エラーは、float を呼び出そうとしていることを示しています。3(...)

このエラーは次の方法で再現できます。

x = [1, 2, 5]
len = 5
len(x)
于 2013-10-17T17:17:49.650 に答える