[英]Add individual distinct points to an existing matplotlib plot in python
有很多方法,但最常见的两种是 patch.Circle( patches.Circle()
和ax.scatter()
。 它们之间的唯一区别是ax.scatter
支持颜色 map。
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import numpy as np
fig = plt.figure(figsize=(8,4.5),dpi=144)
ax = fig.add_subplot(111)
xx = np.random.randint(5,95,(100,))
yy = np.random.randint(75,85,(100,))
ss = np.random.randint(1,5,(100,))
color = ['r','b','g','y','m']
for i,(x,y,s) in enumerate(zip(xx,yy,ss)):
c = patches.Circle(xy=(x, y), radius=s, fc=color[s-1], alpha=0.4)
ax.add_patch(c)
for i,(x,y,s) in enumerate(zip(xx,yy,ss)):
ax.scatter(xx, yy-25, s=s*20, c=yy, cmap='Blues', marker='o', alpha=0.7)
for i,(x,y,s) in enumerate(zip(xx,yy,ss)):
ax.scatter(xx, yy-50, s=50, c='pink', edgecolor='r', marker='o', alpha=0.9)
ax.set_ylim(0,100)
ax.set_xlim(0,100)
ax.set_aspect('equal')
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.