Python - 氣泡圖



氣泡圖將資料顯示為一系列圓圈。建立氣泡圖所需的資料必須具有 xy 座標、氣泡大小和氣泡顏色。顏色可以由庫本身提供。

繪製氣泡圖

可以使用 DataFrame.plot.scatter() 方法建立氣泡圖。

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

它的輸出如下 -

bubblechart.png
廣告
© . All rights reserved.