'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
>>文件: 气泡散点图.py
>>作者: liu yang
>>邮箱: [email protected]
>>博客: www.cnblogs.com/liu66blog ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' #!/usr/bin/env python
# -*- coding: utf-8 -*- import sys, os
import matplotlib.pyplot as plt
import numpy as np
import random # 气泡散点图 bubble
def scatterplot_bubble():
N=80
# 随机获取x<1的数字八十个
x=np.random.rand(N)
# 随机获取y<1的数字八十个
y=np.random.rand(N)
# 定义颜色的列表
colors=['red','green','gray','purple','yellow','orange','blue']
# 随机排列颜色
random_colors=random.sample(colors,7)
# 计算每个随机散点的大小
area=np.pi * (np.random.rand(N)*10)**2
# 绘制散点图
plt.scatter(x,y,c=random_colors,s=area)
# 显示绘制的图
plt.show() # /如果当前模块作为主模块运行
if __name__ == '__main__':
plot=scatterplot_bubble()