python - python - 如何在Pyplot中绘制一个具有n个偶数面积切片的圆?
问题描述
我需要编写一个名为 circ_sectors(n) 的函数,它显示一个带有 n 个切片的圆圈。
例如, circ_sectors(7) 会给我 7 个相等的圆片。
到目前为止,我只能绘制圆圈。
def circ_sectors(n):
angle = np.linspace(0, 2*math.pi, 100)
radius = 1
x = [radius * math.cos(x) for x in angle]
y = [radius * math.sin(x) for x in angle]
plt.axis('equal')
plt.plot(x,y)
解决方案
您已经使用了 cos 和 sin 函数。
现在只需重用这些来找到圆圈的端点?!
for i in range ( n ):
plt.plot( [0, ( math.cos( i * (2*math.pi) / n ) )], [ 0, ( math.sin( i * (2*math.pi) / n ) ) ] )
这绘制了您已经发布的圈子。
这是你想要/需要的吗?
推荐阅读
- thumbnails - 如何在 cs-cart 中更改缩略图创建方式
- flutter - 从 Matrix4 中移除垂直变换
- javascript - 如何停止执行 Firebase 触发的 Firebase 函数?
- javascript - 解构值 nextjs:ReferenceError:初始化前无法访问“XXX”
- ios - 如何将数据从 TextField 从第二个视图控制器发送到第一个视图控制器并将此数据添加到数组 swift iOS
- flutter - Flutter Cursor 同时出现在两个字段中
- jekyll - 我可以在 jekyll 液体中创建和操作地图吗?
- python - POSTGRES:删除 id 前缀的内部连接
- react-native - 为什么 React Native 中没有包含适用于 Android 的 BottomNavigation?
- python-2.7 - 尝试通过 Selenium 和 Python 使用 GeckoDriver Firefox 登录 Gmail 帐户时出现“此浏览器或应用程序可能不安全”错误