注解
Click here 下载完整的示例代码
椭圆演示¶
画许多椭圆。这里画出单个椭圆。将此与 Ellipse collection example .
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(subplot_kw={'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))
ax.set_xlim(0, 10)
ax.set_ylim(0, 10)
plt.show()

椭圆旋转¶
用不同的角度画许多椭圆。
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Ellipse
angle_step = 45 # degrees
angles = np.arange(0, 360, angle_step)
ax = plt.subplot(aspect='equal')
for angle in angles:
ellipse = Ellipse((0, 0), 4, 2, angle=angle, alpha=0.1)
ax.add_artist(ellipse)
plt.xlim(-2.2, 2.2)
plt.ylim(-2.2, 2.2)
plt.show()

工具书类¶
以下函数、方法、类和模块的使用如本例所示:
出:
<function Patch.set_facecolor at 0x7faa167f86a8>
关键词:matplotlib代码示例,codex,python plot,pyplot Gallery generated by Sphinx-Gallery