在Python中,使用 matplotlib 绘制椭圆,可以使用 Ellipse类和 add_artist方法。
编写 test_ellipse.py 如下
# -*- coding: utf-8 -*-
""" 使用Ellipse类绘制椭圆 """
import matplotlib.pyplot as plt
from matplotlib.patches import Ellipse
fig, ax = plt.subplots()
ellipse = Ellipse(xy=(2, 2), width=4, height=3, angle=30, color='red')
# 使用 add_artist方法绘制椭圆
ax.add_artist(ellipse)
ax.set_xlim(0, 6)
ax.set_ylim(0, 8)
plt.grid()
plt.show()
在这个例子中,Ellipse类的参数xy指定了椭圆的中心位置,width和height分别设定了椭圆的长轴和短轴,angle是椭圆的旋转角度,color定义了椭圆的颜色。add_artist方法将椭圆作为图层添加到了坐标轴上。
运行 python test_ellipse.py

《高等数学》同济大学版 P340,编写 test_oval.py 如下
# -*- coding: utf-

最低0.47元/天 解锁文章
3902






