使用matplotlib使用用户输入的点数创建圆图



我真的被难住了,除了示例代码,我真的不知道从哪里开始。我可以想象当输入的整数除以整个360度时需要在这些点上发生什么这意味着会有x;等距角度上的点的数量,除非我也在错误的轨道上。提前感谢大家。

下面是问题提示:开发一个Python程序在窗口中绘制一个圆。首先,导入matplotlib.pyploti.(10点)要求用户输入点的个数来绘制一个圆。定义两个列表,一个到保持每个坐标的x值和另一个y值。x值可以是由余弦决定,y值可以由正弦决定。2(5分)选择图形的样式。3创建两个变量,fig和ax。Use.plot()函数和.scatter()函数函数来绘制数据。iv.(5分)自定义图表,给出轴名和标题。更改的字体大小每个名字和一个头衔。v.(5分)分配线宽和颜色更明显的选择。vi.(5点)最后,显示图表

这是我到目前为止的代码/示例代码:

import matplotlib.pyplot as plt
import math
ky_N = input('Enter the number of segments: ')
ky_x_values = []
ky_y_values = []
ky_n = int(ky_N)
ky_angle = 360 / ky_n
#create for loop
ky_x_values.append()
ky_y_values.append()

您可以运行以下代码来获得所需的内容。我没有添加颜色命令。我相信你可以在网上找到它们,并根据你的喜好添加到它

import matplotlib.pyplot as plt
import numpy as np
# Define the Radius of a circle
R = 1
# Define the number of Edges
n =64
# Subdivide the interval (0, 2*pi) into n points
t = np.linspace(0, 2*np.pi, n+1)
# Take inputs from user
x = input('Enter the value of x')
y = input('Enter the value of y')
# Use cos and sin functions on x and y respectively
x = R*np.cos(t)
y = R*np.sin(t)
# Add axis and labels
plt.title('My title')
plt.xlabel('categories')
plt.ylabel('values')
# Display the circle
plt.axis("equal")
plt.grid()
plt.plot(x,y)
plt.show