Skip to content

Commit acd5806

Browse files
committed
Add an example for scatter plots with auto legends
1 parent ae6bc9a commit acd5806

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

examples/gallery/plot/scatter.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""
2+
Scatter plots with a legend
3+
---------------------------
4+
5+
TODO: Add more docstrings.
6+
7+
Modified from the matplotlib example: https://matplotlib.org/gallery/lines_bars_and_markers/scatter_with_legend.html
8+
"""
9+
10+
import numpy as np
11+
import pygmt
12+
13+
np.random.seed(19680801)
14+
n = 200 # number of random data points
15+
16+
fig = pygmt.Figure()
17+
fig.basemap(
18+
region=[-0.1, 1.1, -0.1, 1.1],
19+
projection="X10c/10c",
20+
frame=["xa0.2fg", "ya0.2fg", "WSrt"],
21+
)
22+
for color in ["blue", "orange", "green"]:
23+
x, y = np.random.rand(2, n) # random X and Y data in [0,1]
24+
sizes = np.random.rand(n) * 0.5 # random size, in cm
25+
# plot data points as circles ('c'), with different sizes
26+
fig.plot(x, y, style="c", sizes=sizes, color=color, label=f"{color}+S0.25c", t=70)
27+
28+
fig.legend(t=30)
29+
fig.show()

0 commit comments

Comments
 (0)