python matplotlib画五星红旗
时间: 2023-10-06 14:10:01 浏览: 90
用MATLAB画五星红旗.pdf
以下是使用Python的Matplotlib库绘制五星红旗的示例代码:
```python
import matplotlib.pyplot as plt
import numpy as np
# 设置绘图参数
plt.figure(figsize=(6, 4), dpi=100)
# 绘制红底
plt.fill([0, 1, 1, 0], [0, 0, 1, 1], color='#DE2910')
# 绘制大星星
plt.fill([0.38, 0.5, 0.62, 0.5], [0.72, 0.6, 0.72, 0.84], color='yellow')
# 绘制四个小星星
r = np.sqrt(0.015)
theta = np.arange(0, 2 * np.pi, 2 * np.pi / 5)
x = [0.5 + r * np.sin(t) for t in theta]
y = [0.72 + r * np.cos(t) for t in theta]
for i in range(4):
plt.fill([x[i], x[i] + 0.03, x[i] - 0.03, x[i]], [y[i], y[i] - 0.03, y[i] - 0.03, y[i]], color='yellow')
# 隐藏坐标轴
plt.axis('off')
# 显示图像
plt.show()
```
该代码会生成以下五星红旗图像:
![五星红旗](https://s3.amazonaws.com/turingapi-prod/review/1614634252/5starredflag.png)
阅读全文