繁体   English   中英

在 python 中将单个不同点添加到现有 matplotlib plot

[英]Add individual distinct points to an existing matplotlib plot in python

我有一个由 matplotlib 生产的 plot ,它显示了随机方程的轨迹。 我希望在现有的 plot 中添加一组单独的点。 有可能这样做吗?

例子

有很多方法,但最常见的两种是 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM