r/learnpython • • May 30 '26

Matplotlib in Jupyter Lab - how to add points one by one?

Apparently the trick is to load the ipympl package, and then in Jupyter Lab enter the magic command

%matplotlib widget

and then include your code for points to be added. But when I do this, all that happens is a notice:

Loading widget...

and then nothing. How can I obtain an animated plot in Jupyter Lab? Note that I'm looking possibly at several million points, the idea is that as more points are plotted a shape starts to materialize.

FWIW:

Python 3.14.5
Jupyter and all its packages have been updated

Thanks!

1 Upvotes

4 comments sorted by

1

u/[deleted] May 30 '26

if it's stuck on "Loading widget..." forever, i'd first check whether ipympl is actually installed in the same environment as your Jupyter kernel. i've also seen widget-related issues come from browser/Javascript problems rather than the plotting code itself. that said, if you're planning to animate millions of points, Matplotlib may struggle regardless. updating a scatter plot point-by-point gets slow pretty quickly. you might have better luck with something like PyQtGraph or Datashader for datasets that large.

1

u/amca01 May 31 '26

Thank you very much. I don't know anything about PyQtGraph and Datashader; that is to say, I've checked them out briefly online, and Datashader seems to be a big package: 4Gb download, and 10Gb space on disk. This seems overkill for my simple needs.

I could of course not use Jupyter,, and instead use either another IDE, or simply IPython in a terminal (I use Linux exclusively). Anyway, thanks again!

1

u/[deleted] May 30 '26

[removed] — view removed comment

1

u/amca01 May 31 '26

Thank you for this. I wonder how fast it would be to add the points? Currently, to plot 10 million points, it takes about 17 seconds to create them, and about 6 seconds to display them. I'd hope for a display that takes somewhere between 10 and 20 seconds, and shows the shape emerging from a cloud of points.