python绘图相关库,绘制各类卡通等图形形象代码
时间: 2023-07-22 12:43:04 浏览: 50
下面是使用matplotlib和turtle库绘制简单卡通图形的示例代码:
使用matplotlib绘制静态图形:
```python
import matplotlib.pyplot as plt
# 绘制圆形
circle = plt.Circle((0, 0), radius=0.5, color='red')
# 绘制矩形
rect = plt.Rectangle((0.2, 0.2), width=0.2, height=0.2, color='blue')
# 创建画布
fig, ax = plt.subplots()
# 添加圆形和矩形到画布
ax.add_artist(circle)
ax.add_artist(rect)
# 设置坐标轴范围
ax.set_xlim([-1, 1])
ax.set_ylim([-1, 1])
# 显示图形
plt.show()
```
使用turtle库绘制简单卡通图形:
```python
import turtle
# 创建画布
t = turtle.Pen()
# 绘制圆形
t.circle(50)
# 绘制眼睛
t.penup()
t.goto(-20, 150)
t.pendown()
t.circle(20)
t.penup()
t.goto(20, 150)
t.pendown()
t.circle(20)
# 绘制嘴巴
t.penup()
t.goto(-50, 100)
t.pendown()
t.setheading(315)
t.circle(70, 90)
# 隐藏画笔
t.hideturtle()
# 显示图形
turtle.mainloop()
```