python如何输入坐标

图片[1]-python如何输入坐标-uusu优素-乐高,模型,3d打印,编程

python利用元组、字典可以表示坐标增减,具体做法为:

defchange_directions(e):#e表示移动方向,list类型
moves={"up":(0,1),"down":(0,-1),"right":(1,0),"left":(-1,0)}
x,y=(0,0)
ife:
forvine:
dx,dy=moves[v]
x+=dx
y+=dy
print((x,y))

或者使用matplotlib绘制极坐标图

创建极坐标图

matplotlib的pyplot子库提供了绘制极坐标图的方法,在调用subplot()创建子图时通过设置projection='polar',便可创建一个极坐标子图,然后调用plot()在极坐标子图中绘图。

下面就创建一个极坐标子图和一个直角坐标子图进行对比。

importmatplotlib.pyplotasplt
ax1=plt.subplot(121,projection='polar')
ax2=plt.subplot(122)
ax1.plot(theta,theta/6,'--',lw=2)
ax2.plot(theta,theta/6,'--',lw=2)
plt.show()
原文来自:https://www.py.cn
© 版权声明
THE END
喜欢就支持一下吧
点赞8 分享