python利用元組、字典可以表示坐標(biāo)增減,具體做法為:
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繪制極坐標(biāo)圖
創(chuàng)建極坐標(biāo)圖
matplotlib的pyplot子庫提供了繪制極坐標(biāo)圖的方法,在調(diào)用subplot()創(chuàng)建子圖時通過設(shè)置projection='polar',便可創(chuàng)建一個極坐標(biāo)子圖,然后調(diào)用plot()在極坐標(biāo)子圖中繪圖。
下面就創(chuàng)建一個極坐標(biāo)子圖和一個直角坐標(biāo)子圖進(jìn)行對比。
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如何輸入坐標(biāo),希望對大家有所幫助,如果想要了解更多Python相關(guān)知識,請關(guān)注IT培訓(xùn)機構(gòu):千鋒教育。