python用以一个函数画奥运五环
时间: 2024-06-10 14:03:46 浏览: 24
Sure, 我知道你想要的! 这是一个 Python 函数来画五环,你可以使用 matplotlib 库:
```python
import matplotlib.pyplot as plt
def draw_olympic_ring():
# 设定五个圆的不同颜色和半径
colors = ['blue', 'black', 'red', 'yellow', 'green']
radii = [50, 45, 40, 35, 30]
# 创建绘图对象
fig, ax = plt.subplots()
# 循环绘制五个圆
for i in range(5):
circle = plt.Circle((i*100, 0), radii[i], color = colors[i], alpha=0.8)
ax.add_artist(circle)
# 设定坐标轴显示
ax.set_xlim(-100,500)
ax.set_ylim(-100,100)
# 显示绘图
plt.show()
draw_olympic_ring()
```
希望这个函数能够帮到你!
相关问题
python用turtle函数画奥运五环
好的,我会用Python的turtle函数来画奥运五环。以下是代码:
```python
import turtle
# 创建窗口
window = turtle.Screen()
window.bgcolor("#ffffff")
# 创建五个画笔,并设置颜色
pen_blue = turtle.Turtle()
pen_blue.color("#00a3e0")
pen_blue.pensize(10)
pen_black = turtle.Turtle()
pen_black.color("#000000")
pen_black.pensize(10)
pen_red = turtle.Turtle()
pen_red.color("#ff2b2b")
pen_red.pensize(10)
pen_yellow = turtle.Turtle()
pen_yellow.color("#fede00")
pen_yellow.pensize(10)
pen_green = turtle.Turtle()
pen_green.color("#009e60")
pen_green.pensize(10)
# 设置五个画笔的位置
pen_blue.penup()
pen_blue.goto(-120, -50)
pen_blue.pendown()
pen_black.penup()
pen_black.goto(0, -50)
pen_black.pendown()
pen_red.penup()
pen_red.goto(120, -50)
pen_red.pendown()
pen_yellow.penup()
pen_yellow.goto(-60, -100)
pen_yellow.pendown()
pen_green.penup()
pen_green.goto(60, -100)
pen_green.pendown()
# 画五个圆环
for pen in [pen_blue, pen_black, pen_red, pen_yellow, pen_green]:
pen.begin_fill()
pen.circle(50)
pen.end_fill()
# 隐藏画笔
pen_blue.hideturtle()
pen_black.hideturtle()
pen_red.hideturtle()
pen_yellow.hideturtle()
pen_green.hideturtle()
# 结束程序
turtle.done()
```
运行代码后,会弹出一个画布,上面画着奥运五环的图案。希望这能解决你的问题。
怎么用python画一个奥运五环
你可以使用Python中的Matplotlib库来绘制奥运五环。下面是绘制五环图的示例代码:
```python
import matplotlib.pyplot as plt
# 设置颜色
colors = ['blue', 'black', 'red', 'yellow', 'green']
# 绘制五个圆
for i in range(5):
# 设置圆心坐标和半径
x, y, r = i * 100 + 60, 60, 40
# 绘制圆
circle = plt.Circle((x, y), r, color=colors[i], fill=False)
# 添加圆到绘图区
plt.gca().add_artist(circle)
# 设置坐标轴范围
plt.xlim(0, 500)
plt.ylim(0, 120)
# 将坐标轴隐藏
plt.axis('off')
# 显示图片
plt.show()
```
运行上述代码,即可在代码编辑器中看到绘制的奥运五环图。