在python中,基于x、y、r作为向量绘制许多圆



x,y是圆的位置,r是半径-所有向量。我想一次把它们都画出来。类似于:

import matplotlib.pyplot as plt
from matplotlib.patches Circle
#define x,y,r vectors
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
plt.Circle((x,y),r,color='r')
plt.show()

谢谢。

plt.scatter允许您定义绘制点的半径。

来自文档

matplotlib.pyplot.scatter(x, y, s=20, c='b', marker='o')
[...]
s:
    size in points^2. It is a scalar or an array of the same length as x and y.

facecoloredgecolor你应该能够得到你想要的

您可以在"如何为matplot散点图中的每个气泡设置_gid()?"中找到一个示例?

我没有被告知Circles补丁,但以下是如何使用标准绘图命令:

import numpy as np
import matplotlib.pyplot as plt
x = np.array([0.2,0.4])
y = np.array([0.2,1.2])
r = np.array([0.5,0.3])
phi = np.linspace(0.0,2*np.pi,100)
na=np.newaxis
# the first axis of these arrays varies the angle, 
# the second varies the circles
x_line = x[na,:]+r[na,:]*np.sin(phi[:,na])
y_line = y[na,:]+r[na,:]*np.cos(phi[:,na])
plt.plot(x_line,y_line,'-')
plt.show()

其基本思想是为plt.plot(...)命令提供两个2D阵列。在这种情况下,它们被解释为一个绘图列表。特别是对于许多绘图(=许多圆),这比逐圆绘图要快得多。

最新更新