|
7 | 7 |
|
8 | 8 | Thanks to Manuel Metz for the example
|
9 | 9 | """
|
10 |
| -import math |
| 10 | + |
11 | 11 | import numpy as np
|
12 | 12 | import matplotlib.pyplot as plt
|
13 | 13 |
|
|
16 | 16 | r2 = r1 + 0.4 # 40%
|
17 | 17 |
|
18 | 18 | # define some sizes of the scatter marker
|
19 |
| -sizes = [60, 80, 120] |
| 19 | +sizes = np.array([60, 80, 120]) |
20 | 20 |
|
21 | 21 | # calculate the points of the first pie marker
|
22 | 22 | #
|
23 | 23 | # these are just the origin (0,0) +
|
24 | 24 | # some points on a circle cos,sin
|
25 |
| -x = [0] + np.cos(np.linspace(0, 2*math.pi*r1, 10)).tolist() |
26 |
| -y = [0] + np.sin(np.linspace(0, 2*math.pi*r1, 10)).tolist() |
27 |
| - |
| 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() |
28 | 27 | xy1 = list(zip(x, y))
|
29 |
| -s1 = max(max(x), max(y)) |
| 28 | +s1 = np.max(xy1) |
30 | 29 |
|
31 |
| -# ... |
32 |
| -x = [0] + np.cos(np.linspace(2*math.pi*r1, 2*math.pi*r2, 10)).tolist() |
33 |
| -y = [0] + np.sin(np.linspace(2*math.pi*r1, 2*math.pi*r2, 10)).tolist() |
| 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() |
34 | 32 | xy2 = list(zip(x, y))
|
35 |
| -s2 = max(max(x), max(y)) |
| 33 | +s2 = np.max(xy2) |
36 | 34 |
|
37 |
| -x = [0] + np.cos(np.linspace(2*math.pi*r2, 2*math.pi, 10)).tolist() |
38 |
| -y = [0] + np.sin(np.linspace(2*math.pi*r2, 2*math.pi, 10)).tolist() |
| 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() |
39 | 37 | xy3 = list(zip(x, y))
|
40 |
| -s3 = max(max(x), max(y)) |
| 38 | +s3 = np.max(xy3) |
41 | 39 |
|
42 | 40 | fig, ax = plt.subplots()
|
43 |
| -ax.scatter(np.arange(3), np.arange(3), marker=(xy1, 0), |
44 |
| - s=[s1*s1*_ for _ in sizes], facecolor='blue') |
45 |
| -ax.scatter(np.arange(3), np.arange(3), marker=(xy2, 0), |
46 |
| - s=[s2*s2*_ for _ in sizes], facecolor='green') |
47 |
| -ax.scatter(np.arange(3), np.arange(3), marker=(xy3, 0), |
48 |
| - s=[s3*s3*_ for _ in sizes], facecolor='red') |
| 41 | +ax.scatter(range(3), range(3), marker=(xy1, 0), |
| 42 | + s=s1 ** 2 * sizes, facecolor='blue') |
| 43 | +ax.scatter(range(3), range(3), marker=(xy2, 0), |
| 44 | + s=s2 ** 2 * sizes, facecolor='green') |
| 45 | +ax.scatter(range(3), range(3), marker=(xy3, 0), |
| 46 | + s=s3 ** 2 * sizes, facecolor='red') |
49 | 47 |
|
50 | 48 | plt.show()
|
0 commit comments