jupyter notebook绘制玫瑰花代码
时间: 2024-10-09 13:01:04 浏览: 60
在Jupyter Notebook中绘制玫瑰花通常使用matplotlib库,这是一个非常流行的数据可视化工具。下面是一个简单的Python代码示例,展示如何用matplotlib的pyplot模块绘制玫瑰图:
```python
import matplotlib.pyplot as plt
from numpy import arange
# 创建数据点
angles = arange(0, 2 * np.pi, 0.01)
r = 1 + np.sin(5 * angles)
# 创建玫瑰图
fig, ax = plt.subplots()
ax.plot(r * np.cos(angles), r * np.sin(angles))
ax.axis('equal') # 确保图形是正方形的,不是椭圆形的
ax.set_title("Rose Curve")
ax.set_xlabel('x')
ax.set_ylabel('y')
# 添加花瓣装饰
for i in range(5):
t = i * (2 * np.pi / 5) # 花瓣的角度
ax.annotate('', xy=(np.cos(t), np.sin(t)), xytext=(-.2, .2),
arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=.2"))
plt.show()
```
这段代码首先生成了一个螺旋形的数据点,然后创建了一个新的图形并设置了轴标签。最后,它绘制了曲线,并添加了一些箭头作为花瓣的装饰。
阅读全文
相关推荐














