本博文源于《python数据可视化》(黑马程序员编著)。旨在讲解python如何使用scatter函数进行绘画散点图和气泡图。先讲解scatter函数参数如何使用,然后再演示两个例子进行绘画散点图和气泡图
scatter(x,y,s=None,c=None,marker=None,cmap=None,norm=None,
vmin=None,vmax=None,alpha=None,linewidths=None,verts=None,
edgecolors=None,*,plotnonfinite=False,data=None,**kwargs)
该函数常用参数如下:
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.rcParams['font.sans-serif'] = ['SimHei']
mpl.rcParams['axes.unicode_minus'] = False
num = 50
x = np.random.rand(num)
y = np.random.rand(num)
plt.scatter(x,y)
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.rcParams['font.sans-serif'] = ['SimHei']
mpl.rcParams['axes.unicode_minus'] = False
num = 50
area = (30* np.random.rand(num)) ** 2
x = np.random.rand(num)
y = np.random.rand(num)
plt.scatter(x,y,s=area)