4

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.

3
  • I'm not sure what you're referring to as a scatter plot object, but when you call plt.scatter, the function accepts a keyword argument s, which you can use to dictate the marker's size. You may also want to change linewidth.
    – Praveen
    Commented Jul 8, 2014 at 8:37
  • @Praveen : I want to be able to change the marker size after plotting without having to clear the axes and re-plot.
    – M. Toya
    Commented Jul 8, 2014 at 10:02
  • I'm not able to find a way to change the markers' sizes after they've been plotted. But as an aside, I have been able to make fast real time (line) plots in the past. I used to save the lines every time they were plotted, and delete them from the axis before plotting a new set (without actually calling clf on the figure). I'd then use draw() to re-draw the axis. All this with plt.ion() of course. Perhaps you can find a similar method with scatter.
    – Praveen
    Commented Jul 8, 2014 at 10:14

2 Answers 2

5

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

5

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.