May 2017
Intermediate to advanced
310 pages
8h 5m
English
Another variant of the scatter plot is the bubble chart. In a scatter plot, we only plot the x, y points of the data. Bubble charts add another dimension by illustrating the size of the points. This third dimension may represent sizes of markets or even profits:
import numpy as np import matplotlib.pyplot as plt n = 10 x = np.random.rand(n) y = np.random.rand(n) colors = np.random.rand(n) area = np.pi * (60 * np.random.rand(n))**2 plt.scatter(x, y, s=area, c=colors, alpha=0.5) plt.show()
With the variable n, we specify the number of randomly generated x and y values. This same number is used to determine the random colors for our x and y coordinates. Random bubble sizes are determined by area = np.pi * (60 * np.random.rand(n))**2 ...