Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 71771ea

Browse filesBrowse files
authored
Merge pull request #14110 from anntzer/scatter_piecharts
Simplify scatter_piecharts example.
2 parents 21380fd + 3ff76e3 commit 71771ea
Copy full SHA for 71771ea

File tree

Expand file treeCollapse file tree

1 file changed

+14
-19
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+14
-19
lines changed

‎examples/lines_bars_and_markers/scatter_piecharts.py

Copy file name to clipboardExpand all lines: examples/lines_bars_and_markers/scatter_piecharts.py
+14-19Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.