Alternative Plotting Backend
Describe the functionality you would like to see.
An alternative plotting backend would be nice, even if it is only experimental. The main goal would be to add support for a GPU based backend which potentially would be much faster than matplotlib especially for larger plots/ images with more that 512 x512 pixels.
I've been playing around with fastplotlib and it looks quite nice, isn't based on OpenCL and while fairly new seems to have quite a few of the features we need. It also isn't terribly hard to add features/ performance optimizations are largely "under the hood".
Maybe just to scope out what a feature complete package would need.
Plotting
- [ ] Scale bars https://github.com/fastplotlib/fastplotlib/issues/743
- [x] 2D Plotting
- [x] 1D Plotting
- [ ] Log Scales
- [ ] 2D Plotting with non linear scales
- [x] Click Events/ arrow events
ROIs
- [x] Rectangle Selector
- [ ] Circle Selector https://github.com/fastplotlib/fastplotlib/issues/742
- [x] Polygon Selector
Markers
- [x] Points plotting
- [x] Texts Plotting
- [x] Lines Plotting
- [ ] Custom Marker plotting
- [ ] Inset figure plotting (not supported as a collection)
Describe the context
Even if everything isn't implemented we could start thinking about what it would take. I think it's actually not terribly much beyond some basic abstraction with the plotting code. The other nice thing this would add is a very responsive plotting option in the browser usingjupyter_rfb which would be quite nice.
Hi! Cool to see your interest, just a few notes:
Logarithmic projections aren't implemented yet, I'm guessing it will require implementing log functions within the camera matrix: https://github.com/pygfx/pygfx/issues/739
We have a hidden early implementation of a polygon selector, only with vertices and edges, no fill area since we'd need to look into triangulation methods and mesh morphing (possibly using this, Almar can probably comment more on it if you choose to implement it).
An elegant per-vertex marker API isn't possible yet: https://github.com/pygfx/pygfx/issues/48#issuecomment-2213447462 . There's a PR which allows adding an entire scatter with a defined marker, but no array-like slicing of markers, we'd prefer to have array-like slicing of markers since that's how all other graphic properties behave.
Inset figure plotting
I hadn't thought of this but it's actually easy to make it part of https://github.com/fastplotlib/fastplotlib/pull/740 if we allow overlaps if the user wants them!
Indeed the integration with jupyter_rfb make it significantly more attractive than other plotting libraries.
Another situation where plotting performance is problematic is plotting EDS signal with markers, because it can be very slow when there are many EDS lines... also if it was possible plot colour coded Gaussian peaks instead of the marker line that would be very useful for the interpretation of EDS spectra, but this may not straightforward! 😅 🙈
@CSSFrancis, please let me know if you think it is worth having a call to discuss the changes that would be needed to the plotting layer in hyperspy.
plotting EDS signal with markers, because it can be very slow when there are many EDS lines... also if it was possible plot colour coded Gaussian peaks instead of the marker line that would be very useful for the interpretation of EDS spectra, but this may not straightforward! 😅 🙈
Sounds like this would just be color slicing? (you can do numpy-like slicing of line graphics properties like colors): https://www.fastplotlib.org/ver/dev/_gallery/line/line_colorslice.html#sphx-glr-gallery-line-line-colorslice-py
A modest GPU can typically handle lines with a total of several million vertices before things slow down
@ericpre Setting up a call would probably be a good idea. I can send you an email.
@kushalkolar several million verticies sounds pretty good. I don't think there are really any applications that we are supporting with anywhere near than number.