|
角度の異なる多くの楕円を描画します。
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Ellipse
delta = 45.0 # degrees
angles = np.arange(0, 360 + delta, delta)
ells = [Ellipse((1, 1), 4, 2, a) for a in angles]
a = plt.subplot(111, aspect='equal')
for e in ells:
e.set_clip_box(a.bbox)
e.set_alpha(0.1)
a.add_artist(e)
plt.xlim(-2, 4)
plt.ylim(-1, 3)
plt.show()

Python 3.11.6 では、下記のような警告が表示されていました。
M:\_________s\Ellipses_02.py:8: MatplotlibDeprecationWarning:
Passing the angle parameter of __init__() positionally is deprecated since Matplotlib 3.6;
the parameter will become keyword-only two minor releases later.
ells = [Ellipse((1, 1), 4, 2, a) for a in angles]
Python 3.12.0 では、下記のようなエラーが表示されて、実行されません。
File "E:\_______\Ellipses_02.py", line 8, in
ells = [Ellipse((1, 1), 4, 2, a) for a in angles]
^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Ellipse.__init__() takes 4 positional arguments but 5 were given
Python 3.12.0 で、実行できるように、KeyWord 引数に書き換えるとエラーなくなりました。
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Ellipse
delta = 45.0 # degrees
angles = np.arange(0, 360 + delta, delta)
# ells = [Ellipse((1, 1), 4, 2, a) for a in angles]
ells = [Ellipse(xy=(1, 1), width=4, height=2, angle=b) for b in angles]
a = plt.subplot(111, aspect='equal')
for e in ells:
e.set_clip_box(a.bbox)
e.set_alpha(0.1)
a.add_artist(e)
plt.xlim(-2, 4)
plt.ylim(-1, 3)
plt.show()

|