r/Python • u/Embarrassed-Mix6420 • Sep 02 '24
Showcase Why not just get your plots in numpy?!
Seriously, that's the question!
Why not just have simpleplot1(values,size,title, scatter=True, pt_color, ...)->np.ndarray
function API that gives you your plot (parts like figure and grid, axis, labels, etc) as numpy arrays for you to overlay, mask, render, stretch, transform, etc how you need with your usual basic array/tensor operations at whatever location of the frame/canvas/memory you need?
Sample implementation: https://github.com/bedbad/justpyplot
What my project does?
Just implements the function above
When I render it, it already beats matplotlib and not by a small margin and it's not the ideal yet:
Plotting itself done in vectorized approach and can be done right utilising the GPUs fully
plot1, plot2 .. plotN is just dependency dimensionality you're plotting (1D values, 2D, add more can add more if wanted)
Target Audience? What it Compares against?
Whoever needs real-time or composable or standalone plotting library or generally use and don't like performance of matplotlib [1, 2, 3]
I use something similar thing based on that for all of my work plotting needs and proved to be useful in robotics where you have a physical feedback loop based on the dependency you're plotting when you manipulating it by hand such as steering the drone;
Take a look at the package - this approach may go deeper and cure the foundational matplotlib vices
It makes it a standalone library : pip install justpyplot
48
u/Noobfire2 Sep 03 '24
Very nice project! A few remarks from a Staff Level Python engineer trying to help:
__pycache__directories or.pycfiles. In fact, add this to a.gitignore.__init__.py. Right now, you're forcing users to write redundant, verbose import statements. Explicit exposing of specific symbols can be done with__all__.setup.pyand separaterequirements.txtfile here. Just go for a modernpyproject.tomlthat can hold all required information, without the need to violating the DRY principle. If you ever need to distribute binary compoments (which you don't do right now), have a look at PEP 517.black+isort, or better yet,ruff format.43
u/Gullible_Carry1049 Sep 02 '24
It think it would be ideal to build this package around the Array API instead of Numpy specifically and then you could work natively with PyTorch tensors without having to cast to numpy arrays first
24
u/TitaniumWhite420 Sep 02 '24
Been a minute since I’ve seen something so substantive and useful posted to this sub. Looks cool.
4
u/jkua Sep 03 '24
I generally use pyqtgraph for my realtime plotting needs. I don’t know if it supports all your needs, but it’s been great for me. It does require Qt, though.
2
u/Peacekeep3r Sep 03 '24
fantastic! Can I use it in a pyvista window?
2
u/ExdigguserPies Sep 03 '24
Looks amazing and I love anything that moves away from matplotlib.
One thing though, why call it pyplot when
matplotlib.pyplotexists? Kinda confusing no?7
u/proverbialbunny Data Scientist Sep 03 '24
This is a really cool idea. I'm impressed.
I've had to do 30 fps 3D plotting before for live sensor diagnostics and my solution was to move away from Python into R as R has some better plotting libraries that are fast enough for it. It's cool to see this kind of speed in Python.
1
u/ThatSituation9908 Sep 05 '24
So, how do you get the axis and labels? Is everything in the output array and we just guess what the dimensions are?
1
u/[deleted] Sep 13 '24
Hey! Cool project. Just a note, when you want to type hint a numpy array, the type is
np.ndarray.np.arrayis the function that creates an array.5
u/OreShovel Sep 02 '24
This is awesome, great stuff!
1
u/drbobb Sep 03 '24 edited Sep 03 '24
Your requirements are missing
perf_timer.The sample code in the README has an error:
NameError: name 't0' is not defined.The
demo.pyalso wants to importscreeninfo.The venv I'm using has already grown to over a gigabyte and I still can't get any sample code to run.
Update: I did get examples/demo.py to run after downloading some more modules from pypi, but all it does is show a window with the picture from my laptop's camera in it. I don't think that was intended.
2
u/dev-ai Sep 03 '24
I really like this. Great work
2
u/ForkLiftBoi Sep 03 '24
Woah this is awesome - also the sample implementation has a typo in the “installation” header. It’s missing an L
This looks great!