我想把一系列的坐标从一条连续的线变成一条特定的曲线。在
Input arrays:
layerdict['Xc'] = [50.6, 69.4, 69.4, 50.6, **50.6**, **50.2**, 69.8, 69.8, 50.2, **50.2**, **69.053**, 69.12, 69.12]
layerdict['Yc'] = [50.6, 50.6, 69.4, 69.4, **50.6**, **50.2**, 50.2, 69.8, 69.8, **50.2**, **50.88**, 50.996, 51.796]
**仅用于视觉目的
我想改变线的颜色,从(50.6,50.6)到(50.2,50.2)和(50.2,50.6)到(69.0535088)等等。。。最好的办法是什么?我有一个条件语句,可以检测then条件并插入空值或其他操作
这是我到目前为止的情况。在
layerdict = {'Xc': [], 'Yc': [], 'Xt': [], 'Yt': []}
with open(inputfilepath, 'r') as ifile:
for item in ifile:
gonematch = gonepattern.match(item)
gtrmatch = gtrpattern.match(item)
if gonematch:
tlist = item.split(' ')
layerdict['Xc'].append(float(tlist[1][1:]))
layerdict['Yc'].append(float(tlist[2][1:]))
elif gtrmatch:
tlist = item.split(' ')
layerdict['Xt'].append(float(tlist[1][1:]))
layerdict['Yt'].append(float(tlist[2][1:]))
plt.plot(layerdict['Xc'], layerdict['Yc'], label='linepath', linewidth=3.5)
plt.xlabel('X')
plt.ylabel('Y')
plt.show(block=True)
示例输入文件如下所示(仅供参考,我从中提取坐标)
^{pr2}$
我会使用numpy的ma模块中的屏蔽数组。虽然numpy数组在索引和数学方面已经比简单列表好,但是掩码数组只在掩码值为False的地方自动绘制。但是,您仍然可以通过使用data属性来检索整个无掩码数组,因此先绘制整个数组,然后只绘制一个子集,只需使用两个几乎相同的plot命令即可:
相关问题 更多 >
编程相关推荐