python绘制封闭多边形教程
数据格式:(polygon.txt)里面含有2个多边形,一行是一个点
0.085,0.834,
0.024,0.744,
0,0.63,
0.024,0.516,
0.085,0.427,
0.5,0.02,
0.675,0.191,
0.795,0.071,
0.815,0.052,
0.835,0.032,
0.84,0.026,
0.844,0.022,
0.856,0.012,
0.871,0.005,
0.886,0.001,
0.903,0,0.823,0.061,
0.823,0.062,
0.826,0.061,
importpylabaspy importtime frompylabimport* frommatplotlib.font_managerimportFontProperties importmatplotlib.pyplotasplt font=FontProperties(fname=r"c:\windows\fonts\simsun.ttc",size=14) defreaddata(ls): l=ls.split(',') iflen(l)>2: return[l[0],l[1]] else: returnNone if"__main__"==__name__: print(9) file_obj=open('fanmaker.txt') k=0 line=file_obj.readline() polygon=[] whileline: k+=1 px=[] py=[] whileline: row=readdata(line) print(line) px.append(row[0]) py.append(row[1]) line=file_obj.readline() ifline=='\n': ps=[] px.append(px[0]) py.append(py[0]) ps.append(px) ps.append(py) polygon.append(ps) line=file_obj.readline() break x=np.array(polygon[0][0]) y=np.array(polygon[0][1]) ##plt.fill(x,y,'b') plt.plot(x,y,'b-',linewidth=2) foriinrange(len(polygon)-1): x=np.array(polygon[i+1][0]) y=np.array(polygon[i+1][1]) ##plt.fill(x,y,'b') plt.plot(x,y,'r-',linewidth=2) plt.hold(True) ##plt.show() x1=[-0.5,1.5] x2=[-0.5,-0.5] x3=[1.5,-0.5] x4=[1.5,1.5] plt.plot(x1,x2,'-') plt.plot(x2,x3,'-') plt.plot(x3,x4,'-') plt.plot(x4,x1,'-') plt.axis([-0.5,1.5,-0.5,1.5]) plt.show() #plt.axis('tight') file_obj.close()
以上这篇python绘制封闭多边形教程就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。