Skip to content

Commit 3ff76e3

Browse files
committed
Simplify scatter_piecharts example.
1 parent e285dde commit 3ff76e3

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

examples/lines_bars_and_markers/scatter_piecharts.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
This example makes custom 'pie charts' as the markers for a scatter plot.
77
8-
Thanks to Manuel Metz for the example
8+
Thanks to Manuel Metz for the example.
99
"""
1010

1111
import numpy as np
@@ -19,31 +19,26 @@
1919
sizes = np.array([60, 80, 120])
2020

2121
# 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])])
2826
s1 = np.abs(xy1).max()
2927

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])])
3331
s2 = np.abs(xy2).max()
3432

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])])
3836
s3 = np.abs(xy3).max()
3937

4038
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')
4742

4843
plt.show()
4944

0 commit comments

Comments
 (0)