Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在圆的圆周上绘制点,但呈椭圆_Python_Arrays_Matplotlib_Geometry_Scatter Plot - Fatal编程技术网

Python 在圆的圆周上绘制点,但呈椭圆

Python 在圆的圆周上绘制点,但呈椭圆,python,arrays,matplotlib,geometry,scatter-plot,Python,Arrays,Matplotlib,Geometry,Scatter Plot,我用python编写了一个代码,在圆周上每隔10度生成一个点: rad = 75 originX = originY = 0 tenDegreePts = [[],[]] for theta in range(0, 360, 10): b = (np.cos(theta))*rad a = (np.sin(theta))*rad tenDegreePts[0].append(originX+b) tenDegreePts[1].append(originY+a)

我用python编写了一个代码,在圆周上每隔10度生成一个点:

rad = 75
originX = originY = 0
tenDegreePts = [[],[]]

for theta in range(0, 360, 10):
    b = (np.cos(theta))*rad
    a = (np.sin(theta))*rad
    tenDegreePts[0].append(originX+b)
    tenDegreePts[1].append(originY+a)

plt.plot(tenDegreePts[0],tenDegreePts[1],'o')
plt.ylim(-100,100)
plt.xlim(-100,100)
程序运行得很好,但由于某些原因,圆的形状更像是椭圆形。此外,图表上的点之间的距离也不相等:

圆周上每10度点的散点图:

在图片中,您看不到轴,但它们在x和y上都从-100变为100

您可以使用plt.axis'equal'来保持绘图的正确纵横比

关于点间距不均匀的问题:以度为单位给出θ,但三角函数的输入以弧度为单位。您可以将度转换为弧度乘以180再除以Pi,如代码中所示

我还重写了一些代码,以便更好地使用技巧

将matplotlib.pyplot作为plt导入 将numpy作为np导入 originX=originY=0 θ=np.0,360,37 对于范围为15、85、10的rad: tenDegreePtsX=np.costheta*np.pi/180*rad+originX tenDegreePtsY=np.sintheta*np.pi/180*rad+原始 plt.plottenDegreePtsX,tenDegreePtsY,'o',ms=rad/10 plt.ylim-100100 plt.xlim-100100 plt.轴“相等” 节目 检查哪一个正好显示了这一点

在这里为不熟悉如何阅读文档的人复制

import matplotlib.pyplot as plt
import numpy as np

# Plot circle of radius 3.

an = np.linspace(0, 2 * np.pi, 100)
fig, axs = plt.subplots(2, 2)

axs[0, 0].plot(3 * np.cos(an), 3 * np.sin(an))
axs[0, 0].set_title('not equal, looks like ellipse', fontsize=10)

axs[0, 1].plot(3 * np.cos(an), 3 * np.sin(an))
axs[0, 1].axis('equal')
axs[0, 1].set_title('equal, looks like circle', fontsize=10)

axs[1, 0].plot(3 * np.cos(an), 3 * np.sin(an))
axs[1, 0].axis('equal')
axs[1, 0].set(xlim=(-3, 3), ylim=(-3, 3))
axs[1, 0].set_title('still a circle, even after changing limits', fontsize=10)

axs[1, 1].plot(3 * np.cos(an), 3 * np.sin(an))
axs[1, 1].set_aspect('equal', 'box')
axs[1, 1].set_title('still a circle, auto-adjusted data limits', fontsize=10)

fig.tight_layout()

plt.show()