|
5 | 5 |
|
6 | 6 | This example makes custom 'pie charts' as the markers for a scatter plot.
|
7 | 7 |
|
8 |
| -Thanks to Manuel Metz for the example |
| 8 | +Thanks to Manuel Metz for the example. |
9 | 9 | """
|
10 | 10 |
|
11 | 11 | import numpy as np
|
|
19 | 19 | sizes = np.array([60, 80, 120])
|
20 | 20 |
|
21 | 21 | # calculate the points of the first pie marker
|
22 |
| -# |
23 |
| -# these are just the origin (0,0) + |
24 |
| -# some points on a circle cos,sin |
25 |
| -x = [0] + np.cos(np.linspace(0, 2 * np.pi * r1, 10)).tolist() |
26 |
| -y = [0] + np.sin(np.linspace(0, 2 * np.pi * r1, 10)).tolist() |
27 |
| -xy1 = np.column_stack([x, y]) |
| 22 | +# these are just the origin (0,0) + some points on a circle cos,sin |
| 23 | +x1 = np.cos(2 * np.pi * np.linspace(0, r1)) |
| 24 | +y1 = np.sin(2 * np.pi * np.linspace(0, r1)) |
| 25 | +xy1 = np.row_stack([[0, 0], np.column_stack([x1, y1])]) |
28 | 26 | s1 = np.abs(xy1).max()
|
29 | 27 |
|
30 |
| -x = [0] + np.cos(np.linspace(2 * np.pi * r1, 2 * np.pi * r2, 10)).tolist() |
31 |
| -y = [0] + np.sin(np.linspace(2 * np.pi * r1, 2 * np.pi * r2, 10)).tolist() |
32 |
| -xy2 = np.column_stack([x, y]) |
| 28 | +x2 = np.cos(2 * np.pi * np.linspace(r1, r2)) |
| 29 | +y2 = np.sin(2 * np.pi * np.linspace(r1, r2)) |
| 30 | +xy2 = np.row_stack([[0, 0], np.column_stack([x2, y2])]) |
33 | 31 | s2 = np.abs(xy2).max()
|
34 | 32 |
|
35 |
| -x = [0] + np.cos(np.linspace(2 * np.pi * r2, 2 * np.pi, 10)).tolist() |
36 |
| -y = [0] + np.sin(np.linspace(2 * np.pi * r2, 2 * np.pi, 10)).tolist() |
37 |
| -xy3 = np.column_stack([x, y]) |
| 33 | +x3 = np.cos(2 * np.pi * np.linspace(r2, 1)) |
| 34 | +y3 = np.sin(2 * np.pi * np.linspace(r2, 1)) |
| 35 | +xy3 = np.row_stack([[0, 0], np.column_stack([x3, y3])]) |
38 | 36 | s3 = np.abs(xy3).max()
|
39 | 37 |
|
40 | 38 | fig, ax = plt.subplots()
|
41 |
| -ax.scatter(range(3), range(3), marker=xy1, |
42 |
| - s=s1 ** 2 * sizes, facecolor='blue') |
43 |
| -ax.scatter(range(3), range(3), marker=xy2, |
44 |
| - s=s2 ** 2 * sizes, facecolor='green') |
45 |
| -ax.scatter(range(3), range(3), marker=xy3, |
46 |
| - s=s3 ** 2 * sizes, facecolor='red') |
| 39 | +ax.scatter(range(3), range(3), marker=xy1, s=s1**2 * sizes, facecolor='blue') |
| 40 | +ax.scatter(range(3), range(3), marker=xy2, s=s2**2 * sizes, facecolor='green') |
| 41 | +ax.scatter(range(3), range(3), marker=xy3, s=s3**2 * sizes, facecolor='red') |
47 | 42 |
|
48 | 43 | plt.show()
|
49 | 44 |
|
|
0 commit comments