import matplotlib.pyplot as plt\nimport numpy as np\n\n# 创建一个被等分成200个弧段的圆\ntheta = np.linspace(0, 2 * np.pi, 200)\nradius = 1\nx = radius * np.cos(theta)\ny = radius * np.sin(theta)\n\n# 随机生成每个弧段的颜色\ncolors = ['red', 'green', 'yellow']\nsegment_colors = np.random.choice(colors, size=200)\n\n# 绘制圆圈并给不同的弧段添加颜色\nfig, ax = plt.subplots(figsize=(6, 6))\nax.plot(x, y, color='black')\n\nfor i in range(200):\n ax.fill_between([x[i], x[i+1]], [y[i], y[i+1]], color=segment_colors[i])\n\n# 设置坐标轴范围\nax.set_xlim(-1.2, 1.2)\nax.set_ylim(-1.2, 1.2)\n\n# 移除坐标轴标签\nax.set_xticks([])\nax.set_yticks([])\n\n# 保存为png文件\nplt.savefig('colored_circle.png', dpi=300)\nplt.show()


原文地址: https://www.cveoy.top/t/topic/ppNh 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录