[英]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.