如何在具有平方单元格的python中显示网格?

问题描述 投票:0回答:1

我想在python的网格上绘制一个圆。我只需要python来显示带有平方单元格的网格。我编写了以下代码,但它显示了具有非平方单元格的网格。

谁能告诉我如何使网格单元平方吗?

import numpy as npimport matplotlib.pyplot as pltimport math

p=8

R=0.484*p

t=np.linspace(0, 2*np.pi)

x=R*np.cos(t)y=R*np.sin(t)

plt.axis("equal")

plt.grid(True, which='both', axis='both')

plt.plot(x,y)plt.show()enter image description here

python numpy geometry grid cell
1个回答
0
投票

如果在plt.grid()之后添加此行,它将写出所有x线,并且正方形将被平方:

plt.xticks(range(-6, 6))

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.