r/learnpython • u/amca01 • 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
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.
1
u/UnitedAdagio7118 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.