用 Python 画出一个400米的椭圆塑的胶跑道图
时间: 2023-05-12 19:02:38 浏览: 81
以下是用 Python 画出一个400米的椭圆塑的胶跑道图的代码:
```python
import matplotlib.pyplot as plt
import numpy as np
# 设置椭圆的长轴和短轴
a = 100
b = 50
# 生成椭圆上的点
t = np.linspace(0, 2*np.pi, 100)
x = a * np.cos(t)
y = b * np.sin(t)
# 绘制椭圆
fig, ax = plt.subplots()
ax.plot(x, y)
# 设置坐标轴范围
ax.set_xlim(-120, 120)
ax.set_ylim(-60, 60)
# 绘制起点和终点
ax.scatter(x[0], y[0], c='r', label='Start')
ax.scatter(x[-1], y[-1], c='g', label='End')
# 添加图例
ax.legend()
# 显示图像
plt.show()
```
希望这个代码对你有帮助!
相关问题
用 Python 画出一个400米的标椎的塑胶跑道图
以下是 Python 代码,可以画出一个400米的标准塑胶跑道图:
```python
import turtle
# 设置画布大小和背景颜色
turtle.setup(800, 800)
turtle.bgcolor("white")
# 设置画笔颜色和粗细
turtle.pensize(3)
turtle.pencolor("blue")
# 画出外圈跑道
turtle.penup()
turtle.goto(0, -200)
turtle.pendown()
turtle.circle(200)
# 画出内圈跑道
turtle.penup()
turtle.goto(0, -180)
turtle.pendown()
turtle.circle(180)
# 画出起点和终点线
turtle.penup()
turtle.goto(-200, 0)
turtle.pendown()
turtle.forward(400)
# 画出标志线
turtle.penup()
turtle.goto(-180, 0)
turtle.pendown()
turtle.forward(360)
# 画出中央分隔线
turtle.penup()
turtle.goto(0, -200)
turtle.pendown()
turtle.setheading(90)
turtle.forward(400)
# 完成画图
turtle.done()
```
希望这个代码能够帮到你!
用python + matplotlib画一个椭圆
以下是使用Python Matplotlib库绘制椭圆的示例代码:
```python
import matplotlib.pyplot as plt
import numpy as np
# 创建一个椭圆的参数方程
def ellipse(x, y, a, b, angle):
theta = np.deg2rad(angle)
xn = x * np.cos(theta) - y * np.sin(theta)
yn = x * np.sin(theta) + y * np.cos(theta)
return (a * xn, b * yn)
# 设置椭圆参数
a = 3
b = 2
angle = 30
# 生成椭圆上的点
t = np.linspace(0, 2*np.pi, 100)
x = a * np.cos(t)
y = b * np.sin(t)
x, y = ellipse(x, y, a, b, angle)
# 绘制椭圆
fig, ax = plt.subplots()
ax.plot(x, y)
ax.set_aspect('equal')
plt.show()
```
运行代码后,会生成一个椭圆,并在屏幕上显示。您可以根据需要修改椭圆的参数来调整其大小和形状。