How to draw a rose flower using Python?

To draw a rose using Python, you can use the matplotlib drawing library. Here is a basic example code:

import matplotlib.pyplot as plt
import numpy as np

# 设置画布大小和背景颜色
fig, ax = plt.subplots(figsize=(6, 6), facecolor='white')

# 参数设置
N = 100  # 花瓣的数量
theta = np.linspace(0, 2*np.pi, N, endpoint=False)  # 极坐标角度
r = np.sin(4*theta)  # 极坐标半径

# 极坐标转换为笛卡尔坐标
x = r * np.cos(theta)
y = r * np.sin(theta)

# 绘制花瓣
ax.plot(x, y, color='red', linewidth=2)

# 设置坐标轴范围和隐藏刻度
ax.set_xlim(-1.5, 1.5)
ax.set_ylim(-1.5, 1.5)
ax.set_xticks([])
ax.set_yticks([])

# 隐藏边框
for spine in ax.spines.values():
    spine.set_visible(False)

# 显示图形
plt.show()

This code will draw a rose with 100 petals. You can adjust the parameters to change the shape and size of the rose as needed.

bannerAds