Anaconda绘制椭圆
时间: 2024-03-15 16:40:45 浏览: 65
在Anaconda中,你可以使用Python的绘图库matplotlib来绘制椭圆。下面是一个简单的示例代码:
```python
import matplotlib.pyplot as plt
import numpy as np
# 创建一个椭圆
center = (0, 0) # 椭圆中心坐标
width = 4 # 椭圆宽度
height = 2 # 椭圆高度
angle = 45 # 椭圆旋转角度
# 生成椭圆上的点
t = np.linspace(0, 2*np.pi, 100)
x = center[0] + width/2 * np.cos(t) * np.cos(np.deg2rad(angle)) - height/2 * np.sin(t) * np.sin(np.deg2rad(angle))
y = center[1] + width/2 * np.cos(t) * np.sin(np.deg2rad(angle)) + height/2 * np.sin(t) * np.cos(np.deg2rad(angle)))
# 绘制椭圆
plt.plot(x, y)
plt.axis('equal') # 设置坐标轴比例相等,使椭圆不会被拉伸
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Ellipse')
plt.grid(True)
plt.show()
```
这段代码使用了matplotlib库中的plot函数来绘制椭圆,通过调整椭圆的中心坐标、宽度、高度和旋转角度,可以得到不同形状和位置的椭圆。使用axis函数设置坐标轴比例相等,使椭圆不会被拉伸。最后使用show函数显示绘制的椭圆。
阅读全文
相关推荐












