受这个答案的启发,我试图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
注意:我完全理解我应该让代码“copy-n-paste runnable”,这样你们就可以轻松地帮助发现问题。我已经很努力了,但是奇怪的是,一旦我简化它并使其“复制粘贴可运行”,错误就消失了!所以我没有办法,只能直接发布片段。
什么地方出了错?