I want to draw some circles using `ax3.scatter(x1, y1, s=r1 , facecolors=’none’, edgecolors=’r’), where:
- x1 and y1 are the coordinates of these circles
- r1 is the radius of these circles
I thought typing s = r1
I would get the correct radius, but that’s not the case.
How can I fix this?
Advertisement
Answer
If you change the value of ‘r’ (now 5) to your desired radius, it works. This is adapted from the matplotlib.org website, “Scatter Plots With a Legend”. Should be scatter plots with attitude!
JavaScript
x
20
20
1
import numpy as np
2
import matplotlib.pyplot as plt
3
4
np.random.seed(19680801)
5
6
fig, ax = plt.subplots()
7
for color in ['tab:blue', 'tab:orange', 'tab:green']:
8
r = 5 #radius
9
n = 750 #number of circles
10
x, y = np.random.rand(2, n)
11
#scale = 200.0 * np.random.rand(n)
12
scale = 3.14159 * r**2 #CHANGE r
13
ax.scatter(x, y, c=color, s=scale, label=color,
14
alpha=0.3, edgecolors='none')
15
16
ax.legend()
17
ax.grid(True)
18
19
plt.show()
20