Professional Documents
Culture Documents
The bubble chart in Plotly is created using the scatter plot. It can be
created using the scatter() method of plotly.express. A bubble chart is a
data visualization which helps to displays multiple circles (bubbles) in a
two-dimensional plot as same in scatter plot. A bubble chart is primarily
used to depict and show relationships between numeric variables.
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()
Bubble Plot in Python:
Using Matplotlib, we can make bubble plot in Python using the
scatter() function. To make bubble plot, we need to specify size
argument “s” for size of the data points.
We can see that the points in the scatter plots are bubbles now
based on the value of size variable. By default, Matplotlib
makes the bubble color as blue. We have also added
transparency to the bubbles in the bubble plot using
alpha=0.5.
plt.scatter(x, y, c ="blue")
N = 13
colors = np.random.rand(N)
area = (25 * np.random.rand(N))**2
df = pd.DataFrame({
'X': x,
'Y': y,
'Colors': colors,
"bubble_size":area})
plt.scatter('X', 'Y',
s='bubble_size',
alpha=0.5,
data=df,c=colors)
plt.xlabel("X", size=16)
plt.ylabel("y", size=16)
plt.title("Bubble Plot with Matplotlib", size=18)