python绘制封闭多边形教程数据格式:() ⾥⾯含有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,
import pylab as py
import time
from pylab import *
from matplotlib.font_manager import FontProperties
import matplotlib.pyplot as plt
font = FontProperties(fname=r"c:\windows\", size=14)
def readdata(ls):
l = ls.split(',')
if len(l)>2:
return [l[0],l[1]]
else:
return None
if "__main__"==__name__:
print(9)
file_obj=open('')
k=0
line=adline()
polygon =[]
while line:
k+=1
px=[]
py=[]
while line:
row = readdata(line)
print (line)
px.append(row[0])
py.append(row[1])
line=adline()
if line=='\n':
ps=[]
px.append(px[0])
py.append(py[0])
ps.append(px)
ps.append(py)
polygon.append(ps)
line=adline()
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)
for i in range(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,'-')
python安装教程非常详细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绘制封闭多边形教程就是⼩编分享给⼤家的全部内容了,希望能给⼤家⼀个参考,也希望⼤家多多⽀持。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。