Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update marker sizes of a scatter plot

A scatter plot object has a method called .set_array to update the colours of the markers and .set_offsets to update their position but how can I update the marker sizes?

I need this for fast real time plotting.

like image 785
M. Toya Avatar asked Oct 11 '25 14:10

M. Toya


2 Answers

Yes it is doable, with using a magic method (_size). Use it with caution, as it may become broken in future releases:

from matplotlib import pyplot as plt
import numpy as np

x, y=range(10), range(10)
sca=plt.scatter(x,y)
raw_input()
sca._sizes=(5+np.arange(10))*10 #you can set you markers to different sizes
plt.draw()

enter image description here

like image 192
CT Zhu Avatar answered Oct 14 '25 04:10

CT Zhu


The method to update the sizes of the scatter points is called .set_sizes()

scat = plt.scatter(x,y)
scat.set_sizes(sizes)

where sizes must be an array or list of same length as x and y.

like image 45
ImportanceOfBeingErnest Avatar answered Oct 14 '25 03:10

ImportanceOfBeingErnest