1>>> ax2 = df.plot.scatter(x='length',
2... y='width',
3... c='species',
4... colormap='viridis')
5
1import numpy as npimport matplotlib.pyplot as plt
2# Create data
3N = 500x = np.random.rand(N)
4y = np.random.rand(N)
5colors = (0,0,0)
6area = np.pi*3
7# Plot
8plt.scatter(x, y, s=area, c=colors, alpha=0.5)
9plt.title('Scatter plot pythonspot.com')
10plt.xlabel('x')
11plt.ylabel('y')
12plt.show()
1import matplotlib.pyplot as plt
2import numpy as np
3
4# Fixing random state for reproducibility
5np.random.seed(19680801)
6
7
8N = 100
9r0 = 0.6
10x = 0.9 * np.random.rand(N)
11y = 0.9 * np.random.rand(N)
12area = (20 * np.random.rand(N))**2 # 0 to 10 point radii
13c = np.sqrt(area)
14r = np.sqrt(x ** 2 + y ** 2)
15area1 = np.ma.masked_where(r < r0, area)
16area2 = np.ma.masked_where(r >= r0, area)
17plt.scatter(x, y, s=area1, marker='^', c=c)
18plt.scatter(x, y, s=area2, marker='o', c=c)
19# Show the boundary between the regions:
20theta = np.arange(0, np.pi / 2, 0.01)
21plt.plot(r0 * np.cos(theta), r0 * np.sin(theta))
22
23plt.show()
24
1import numpy as np
2np.random.seed(19680801)
3import matplotlib.pyplot as plt
4
5
6fig, ax = plt.subplots()
7for color in ['tab:blue', 'tab:orange', 'tab:green']:
8 n = 750
9 x, y = np.random.rand(2, n)
10 scale = 200.0 * np.random.rand(n)
11 ax.scatter(x, y, c=color, s=scale, label=color,
12 alpha=0.3, edgecolors='none')
13
14ax.legend()
15ax.grid(True)
16
17plt.show()