![图片[1]-python如何输入坐标-uusu优素-乐高,模型,3d打印,编程](http://uusucn.zbbe.cn/wp-content/uploads/2024/01/5e73566b98911586.jpg)
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


















































暂无评论内容