注意
前往結尾以下載完整範例程式碼。
橢圓示範#
繪製多個橢圓。此處繪製個別的橢圓。請將其與橢圓集合範例進行比較。
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Ellipse
# Fixing random state for reproducibility
np.random.seed(19680801)
NUM = 250
ells = [Ellipse(xy=np.random.rand(2) * 10,
width=np.random.rand(), height=np.random.rand(),
angle=np.random.rand() * 360)
for i in range(NUM)]
fig, ax = plt.subplots()
ax.set(xlim=(0, 10), ylim=(0, 10), aspect="equal")
for e in ells:
ax.add_artist(e)
e.set_clip_box(ax.bbox)
e.set_alpha(np.random.rand())
e.set_facecolor(np.random.rand(3))
plt.show()

旋轉的橢圓#
繪製多個具有不同角度的橢圓。
angle_step = 45 # degrees
angles = np.arange(0, 180, angle_step)
fig, ax = plt.subplots()
ax.set(xlim=(-2.2, 2.2), ylim=(-2.2, 2.2), aspect="equal")
for angle in angles:
ellipse = Ellipse((0, 0), 4, 2, angle=angle, alpha=0.1)
ax.add_artist(ellipse)
plt.show()

參考
此範例中顯示了以下函數、方法、類別和模組的使用
腳本的總執行時間:(0 分鐘 1.751 秒)