How can simple shapes be drawn using Python?
To draw simple shapes with Python, you can utilize Python’s plotting library, matplotlib. Here is an example code using matplotlib to draw a straight line and a circle.
import matplotlib.pyplot as plt
# 绘制直线
x = [0, 1, 2, 3, 4]
y = [0, 2, 4, 6, 8]
plt.plot(x, y)
# 绘制圆形
circle = plt.Circle((5, 5), radius=2, fc='blue')
plt.gca().add_patch(circle)
# 设置图形标题和坐标轴标签
plt.title('Simple Graph')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
# 显示图形
plt.show()
Running the code above will generate a simple graphic window that includes a straight line and a circle. You can modify and expand it as needed to draw more complex graphics.