画一个足球场,尺寸已标注好

画一个有标注的足球场

在这里插入图片描述
上面是一个带有标注的足球场俯视图,下面是实现代码。

import matplotlib.pyplot as plt
from matplotlib.patches import Arc, Circle, Rectangle

# 创建一个灰色背景的子图
fig, ax = plt.subplots(facecolor='grey')

# 设置x轴和y轴的范围
ax.set_xlim(0, 120)
ax.set_ylim(0, 80)

# 关闭坐标轴
ax.axis('off')

# 画出矩形的轮廓和填充色,并添加长度和宽度标注
ax.plot([0, 120, 120, 0, 0], [0, 0, 80, 80, 0], color='darkgreen')
ax.annotate('120 yards', xy=(60, 0), xytext=(60, -2), ha='center', va='top', color='white')
ax.annotate('80 yards', xy=(0, 40), xytext=(-2, 40), ha='right', va='center', color='white', rotation=90)

# 画出中间的纵向线,并添加中线标注
ax.plot([60, 60], [0, 80], color='darkgreen')
ax.annotate('50 yards', xy=(55, 40), xytext=(52, 40), ha='right', va='center', color='white', rotation=90)

# 画出左右两个小矩形,添加尺寸标注
rect1 = Rectangle((0, 30), 6, 20, linewidth=1, edgecolor='white', facecolor='darkgreen')
rect2 = Rectangle((114, 30), 6, 20, linewidth=1, edgecolor='white', facecolor='darkgreen')
ax.add_patch(rect1)
ax.add_patch(rect2)
ax.annotate('20 yards', xy=(3, 40), xytext=(3, 42), ha='center', va='bottom', color='white')
ax.annotate('20 yards', xy=(117, 40), xytext=(117, 42), ha='center', va='bottom', color='white')

# 画出左右两个小圆,添加直径标注
circle1 = Circle((3, 40), 2, linewidth=1, edgecolor='white', facecolor='darkgreen')
circle2 = Circle((117, 40), 2, linewidth=1, edgecolor='white', facecolor='darkgreen')
ax.add_patch(circle1)
ax.add_patch(circle2)
ax.annotate('4 yards', xy=(5, 40), xytext=(5, 42), ha='center', va='bottom', color='white')
ax.annotate('4 yards', xy=(119, 40), xytext=(119, 42), ha='center', va='bottom', color='white')

# 画出左右两个半圆,添加半径标注
arc1 = Arc((12, 40), 20, 20, angle=90, theta1=130, theta2=230, linewidth=1, edgecolor='white')
arc2 = Arc((108, 40), 20, 20, angle=-90, theta1=310, theta2=50, linewidth=1, edgecolor='white')
ax.add_patch(arc1)
ax.add_patch(arc2)
ax.annotate('10 yards', xy=(22, 26), xytext=(22, 24), ha='center', va='top', color='white')
ax.annotate('10 yards', xy=(98, 54), xytext=(98, 56), ha='center', va='bottom', color='white')

# 在中间画出一个小圆点
ax.plot(60, 40, marker='o', markersize=2, color='white')

# 设置子图标题
ax.set_title('Blue Football Field')

# 显示图形
plt.show()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值