椭圆演示

绘制多个椭圆。此处绘制单个椭圆。将其与Ellipse集合示例进行比较。

  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. from matplotlib.patches import Ellipse
  4. NUM = 250
  5. ells = [Ellipse(xy=np.random.rand(2) * 10,
  6. width=np.random.rand(), height=np.random.rand(),
  7. angle=np.random.rand() * 360)
  8. for i in range(NUM)]
  9. fig, ax = plt.subplots(subplot_kw={'aspect': 'equal'})
  10. for e in ells:
  11. ax.add_artist(e)
  12. e.set_clip_box(ax.bbox)
  13. e.set_alpha(np.random.rand())
  14. e.set_facecolor(np.random.rand(3))
  15. ax.set_xlim(0, 10)
  16. ax.set_ylim(0, 10)
  17. plt.show()

椭圆演示

椭圆旋转

绘制许多不同角度的椭圆。

  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. from matplotlib.patches import Ellipse
  4. delta = 45.0 # degrees
  5. angles = np.arange(0, 360 + delta, delta)
  6. ells = [Ellipse((1, 1), 4, 2, a) for a in angles]
  7. a = plt.subplot(111, aspect='equal')
  8. for e in ells:
  9. e.set_clip_box(a.bbox)
  10. e.set_alpha(0.1)
  11. a.add_artist(e)
  12. plt.xlim(-2, 4)
  13. plt.ylim(-1, 3)
  14. plt.show()

椭圆演示2

参考

此示例中显示了以下函数,方法,类和模块的使用:

  1. import matplotlib
  2. matplotlib.patches
  3. matplotlib.patches.Ellipse
  4. matplotlib.axes.Axes.add_artist
  5. matplotlib.artist.Artist.set_clip_box
  6. matplotlib.artist.Artist.set_alpha
  7. matplotlib.patches.Patch.set_facecolor

下载这个示例