簡體   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