python编程实现随机生成多个椭圆实例代码

yipeiwu_com6年前Python基础

椭圆演示:

代码示例:

import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Ellipse

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()

总结

以上就是本文关于python编程实现随机生成多个椭圆实例代码的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题,如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!

相关文章

Django框架模型简单介绍与使用分析

Django框架模型简单介绍与使用分析

本文实例讲述了Django框架模型简单介绍与使用。分享给大家供大家参考,具体如下: ORM介绍 ORM Object relational mapping 对象关系映射 把面向...

python实现两个一维列表合并成一个二维列表

我就废话不多说了,直接上代码吧! >>> list1 = [1,2,3,4,4] >>> list2 = [2,3,4,5,2] >>...

Python Django 实现简单注册功能过程详解

Python Django 实现简单注册功能过程详解

项目创建略,可参考Python Django Vue 项目创建。 目录结构如下 编辑views.py from django.shortcuts import render #...

python求加权平均值的实例(附纯python写法)

首先是数据源: #需要求加权平均值的数据列表 elements = [] #对应的权值列表 weights = [] 使用numpy直接求: import numpy as n...

python得到单词模式的示例

python得到单词模式的示例

如下所示: def getWordPattern(word): pattern = [] usedLetter={} count=0 for i in word: if i...