首页 > 解决方案 > 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)

标签: python

解决方案


您已经使用了 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 ) ) ] )

这绘制了您已经发布的圈子。

这是你想要/需要的吗?


推荐阅读