English 中文(简体)
Python Bubble Charts
  • 时间:2024-11-03

Python - Bubble Charts


Previous Page Next Page  

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 suppped by the pbrary itself.

Drawing a Bubble Chart

Bubble chart can be created using the DataFrame.plot.scatter() methods.

import matplotpb.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()
 

Its output is as follows −

bubblechart.png Advertisements