Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add points to the existing matplotlib scatter plot

How to add points to the existing diagram? The straightforward solution is to plot a new scatter, adding new data.

ax.scatter(data[:,0], data[:,1], cmap = cmap, c = color_data)
ax.scatter(new_points_x, new_points_y, color='blue')

But if we want to add more points with new colors, there is a problem: we have to take into consideration all previously added points.

It would be great if I could use a special function like

AddPoint(ax, new_point, color)

I want only add new points in new colors. I do NOT need any animations

like image 347
toyewonug Avatar asked Nov 16 '25 07:11

toyewonug


1 Answers

To just add a new data with new colour, indeed calling again scatter will add the new points with the specified colour:

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(10)
a = np.random.rand(10)
plt.scatter(x, a, c='blue')
b = np.random.rand(10)
plt.scatter(x, b, c='red')
plt.show()

enter image description here

like image 147
b-fg Avatar answered Nov 18 '25 21:11

b-fg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!