|
1 | 1 | """
|
2 |
| -================= |
3 |
| -Scatter Star Poly |
4 |
| -================= |
| 2 | +=============== |
| 3 | +Marker examples |
| 4 | +=============== |
5 | 5 |
|
6 |
| -Create multiple scatter plots with different |
7 |
| -star symbols. |
| 6 | +Example with different ways to specify markers. |
8 | 7 |
|
| 8 | +For a list of all markers see also the `matplotlib.markers` documentation. |
9 | 9 | """
|
10 | 10 | import numpy as np
|
11 | 11 | import matplotlib.pyplot as plt
|
12 | 12 |
|
13 | 13 | # Fixing random state for reproducibility
|
14 | 14 | np.random.seed(19680801)
|
15 | 15 |
|
16 |
| - |
17 | 16 | x = np.random.rand(10)
|
18 | 17 | y = np.random.rand(10)
|
19 | 18 | z = np.sqrt(x**2 + y**2)
|
20 | 19 |
|
21 |
| -plt.subplot(321) |
22 |
| -plt.scatter(x, y, s=80, c=z, marker=">") |
| 20 | +fig, axs = plt.subplots(2, 3, sharex=True, sharey=True) |
| 21 | + |
| 22 | +# marker symbol |
| 23 | +axs[0, 0].scatter(x, y, s=80, c=z, marker=">") |
| 24 | +axs[0, 0].set_title("marker='>'") |
23 | 25 |
|
24 |
| -plt.subplot(322) |
25 |
| -plt.scatter(x, y, s=80, c=z, marker=(5, 0)) |
| 26 | +# marker from TeX |
| 27 | +axs[0, 1].scatter(x, y, s=80, c=z, marker=r'$\alpha$') |
| 28 | +axs[0, 1].set_title(r"marker=r'\$\alpha\$'") |
26 | 29 |
|
| 30 | +# marker from path |
27 | 31 | verts = np.array([[-1, -1], [1, -1], [1, 1], [-1, -1]])
|
28 |
| -plt.subplot(323) |
29 |
| -plt.scatter(x, y, s=80, c=z, marker=verts) |
| 32 | +axs[0, 2].scatter(x, y, s=80, c=z, marker=verts) |
| 33 | +axs[0, 2].set_title("marker=verts") |
30 | 34 |
|
31 |
| -plt.subplot(324) |
32 |
| -plt.scatter(x, y, s=80, c=z, marker=(5, 1)) |
| 35 | +# regular polygon marker |
| 36 | +axs[1, 0].scatter(x, y, s=80, c=z, marker=(5, 0)) |
| 37 | +axs[1, 0].set_title("marker=(5, 0)") |
33 | 38 |
|
34 |
| -plt.subplot(325) |
35 |
| -plt.scatter(x, y, s=80, c=z, marker='+') |
| 39 | +# regular star marker |
| 40 | +axs[1, 1].scatter(x, y, s=80, c=z, marker=(5, 1)) |
| 41 | +axs[1, 1].set_title("marker=(5, 1)") |
36 | 42 |
|
37 |
| -plt.subplot(326) |
38 |
| -plt.scatter(x, y, s=80, c=z, marker=(5, 2)) |
| 43 | +# regular asterisk marker |
| 44 | +axs[1, 2].scatter(x, y, s=80, c=z, marker=(5, 2)) |
| 45 | +axs[1, 2].set_title("marker=(5, 2)") |
39 | 46 |
|
| 47 | +plt.tight_layout() |
40 | 48 | plt.show()
|
0 commit comments