DEV Community

Samreen
Samreen

Posted on

Streamline Plots: NumPy to Jupyter, No Loops

Tired of writing loops for every plot?

Imagine a world where you can create any kind of plot you desire with a single, powerful function. No more tedious loops, just a clean and concise API that handles everything for you.

Ever get tired of writing endless loops just to make a basic plot? Wouldn't it be awesome to have a super-powered plot1 function that takes your data, throws in some options for size, title, and maybe a scatter plot (with your favorite color!), and spits out a ready-to-go plot you can customize any way you want?

Imagine being able to overlay it, mask it, stretch it, or twist it into any shape – all within the frame, canvas, or memory spot you need. Sounds pretty sweet, right?

Well, guess what? I took this exact idea and slapped it onto a mug-detecting neural network in just three lines of code! (Check out examples/mug_objectron/demo.py for the magic). This lets you play around with the detector in the real world – way cooler than endless loops, wouldn't you say?

examples/mug_objectron/demo.py

Why Use It:

Current Python plotting tools, like Matplotlib (and its clones), make you jump through 3 to 6 steps just to get your plots in an easy-to-work-with array format, like ndarray. Basically, they force you to grab a screenshot of the plot, buffer it back as pixel/image tensors, which slows things down by a few milliseconds every frame—definitely not ideal.

That kind of workflow is a major drag, especially when you need to tweak, render, publish, or create GIFs. It's even worse if you're doing real-time stuff, like physical testing, robotics, or computer vision, where every millisecond counts. The typical approach just isn’t fast enough to handle real-time feedback for things like physical manipulation of your setup or debugging a camera feed.

The code I’m talking about is a fresh, more efficient rewrite that doesn’t suffer from the same issues as Matplotlib. It's vectorized, which is a big deal in the ML/AI space, and can be directly integrated into visual neural networks. Plus, it’s perfect for robotics, where you need to control things in real-time, like steering a drone while adjusting a plot based on the feedback you're getting. It’s a solid tool for real-time plotting and visual debugging in computer vision applications or any scenario where you need a Python plotting library that’s actually composable and doesn’t slow you down.

Instalation

You can copy justpyplot.py file code respecting the license; For use in Jupyter notebooks its convienent to:

pip install justpyplot

Ready to give it a try? Head over to its GitHub repository for more details and to start experimenting with its code.

Top comments (0)