【问题标题】:Creating Circle Plot using matplotlib using amount of points from user input使用 matplotlib 使用用户输入的点数创建圆图
【发布时间】:2021-12-06 21:09:56
【问题描述】:

我真的很困惑,真的不知道从示例代码之外的任何地方可以去哪里。我可以想象当输入整数除以整个 360 度时需要发生什么,这意味着在等距度数处会有“x”个点,除非我在那里也走错了路。提前谢谢大家。

问题提示如下: 开发一个 Python 程序以在窗口中绘制一个圆。 首先,导入 matplotlib.pyplot 一世。 (10 分)要求用户输入点数来绘制一个圆。定义两个列表,一个到 将 x 值和另一个保存到每个坐标的 y 值。 x 值可以是 使用余弦确定,y 值可以使用正弦确定。 ii. (5 分)选择图表使用的样式。 iii. (5 分)创建两个变量,fig 和 ax。使用 .plot() 函数和 .scatter() 绘制数据的函数。 iv. (5 分)自定义图表,给出坐标轴名称和标题。更改字体大小 每个名字和一个头衔。 v. (5 分)指定您选择的线宽和更明显的颜色。 六。 (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()

【问题讨论】:

  • Matplotlib tutorials 可以帮助您入门。您可以调用类似y_k = math.sine(k*angle*math.pi/180) 的方法来获取第 k 个 y 坐标。

标签: python numpy matplotlib plot graph


【解决方案1】:

你可以运行下面的代码来得到你想要的。我没有添加颜色命令。我相信您可以在互联网上找到它们并根据自己的喜好添加它们

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-26
    • 1970-01-01
    • 1970-01-01
    • 2021-10-21
    • 2014-07-18
    相关资源
    最近更新 更多