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繪制極坐標圖
創(chuàng)建極坐標圖
matplotlib的pyplot子庫提供了繪制極坐標圖的方法,在調(diào)用subplot()創(chuàng)建子圖時通過設置projection='polar',便可創(chuàng)建一個極坐標子圖,然后調(diào)用plot()在極坐標子圖中繪圖。
下面就創(chuàng)建一個極坐標子圖和一個直角坐標子圖進行對比。
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()
以上內(nèi)容為大家介紹了python如何輸入坐標,希望對大家有所幫助,如果想要了解更多Python相關知識,請關注IT培訓機構:千鋒教育。