0

I'm doing a numerical optimization, and I want to visualize the loss of the objective function at each iteration, which means I need to add one point when each iteration is done into the plot.

I thought this might be a matplotlib.animation job, but it seems that animation just updates the plot by interval period of time, this is not what I want.

After searching SO, I indeed find a tricky solution, but is there a better way?

Community
  • 1
  • 1
Alcott
  • 17,905
  • 32
  • 116
  • 173
  • using the `set_*data` and `draw` methods isn't too complicated - does it not work for you? If you think that the more performant version is too complicated, you could always consider pyqtgraph. – mdurant Oct 12 '14 at 13:03
  • @mdurant, that works for the `ax.plot` thing, but what about `ax.scatter`? – Alcott Oct 12 '14 at 13:07

1 Answers1

0

To set the data of a scatter in-place, you need to do the following:

pc = ax.scatter( x, y, ...)

and modify:

px.set_offsets( xnew, ynew )

before invoking wither draw (slower) or the blit method you linked.

mdurant
  • 27,272
  • 5
  • 45
  • 74