Python Data Science 简明教程
Python - Bubble Charts
气泡图将数据显示为一堆圆圈。创建气泡图所需的必需数据包括 xy 坐标、气泡大小和气泡颜色。颜色可以由库本身提供。
Bubble charts display data as a cluster of circles. The required data to create bubble chart needs to have the xy coordinates, size of the bubble and the colour of the bubbles. The colours can be supplied by the library itself.
Drawing a Bubble Chart
可以使用 DataFrame.plot.scatter() 方法创建气泡图。
Bubble chart can be created using the DataFrame.plot.scatter() methods.
import matplotlib.pyplot as plt
import numpy as np
# create data
x = np.random.rand(40)
y = np.random.rand(40)
z = np.random.rand(40)
colors = np.random.rand(40)
# use the scatter function
plt.scatter(x, y, s=z*1000,c=colors)
plt.show()
它的 output 如下所示 −
Its output is as follows −