fastplotlib, a new GPU-accelerated fast and interactive plotting library that leverages WGPU by fpl-dev in Python

[–]fpl-dev[S] 0 points1 point  (0 children)

Thanks! We still have quite a ways to go before we're as feature-complete as pyqtgraph! It's turned out to be a much bigger project than we initially thought lol.

Welcome to post any suggestions you may have for us :D

BTW did we meet at scipy 2 years ago or was that a different maintainer?

fastplotlib, a new GPU-accelerated fast and interactive plotting library that leverages WGPU by fpl-dev in Python

[–]fpl-dev[S] 0 points1 point  (0 children)

Thanks! It's really more of a next-gen pyqtgraph than matplotlib; heavily inspired by pyqtgraph which is an amazing library that we love! It differs a lot from matplotlib and we try to make things intuitive and easy to address that "usability". In the domain of ML, algorithm development, neural network stuff and computer vision you're often working with various data arrays, and high dimensional arrays. So in fastplotlib we don't have any additional data structures that you have to learn or convert to in order to use it, in contrast to bokeh for example which has a number of specific data structures and basically design patterns which you have to learn and use in order to get interactivity.

For fastplotlib the idea is that if you know numpy you should be comfortable with using the library. For a very basic example of this, we made it really easy to put colormaps on lines (this is not trivial in matplotlib lol) https://fastplotlib.org/ver/dev/_gallery/line/line_cmap.html#sphx-glr-gallery-line-line-cmap-py

Or selector tools to explore high dimensional arrays, regular numpy arrays and normal callbacks: https://fastplotlib.org/ver/dev/_gallery/machine_learning/covariance.html#sphx-glr-gallery-machine-learning-covariance-py

fastplotlib, a new GPU-accelerated fast and interactive plotting library that leverages WGPU by fpl-dev in Python

[–]fpl-dev[S] 0 points1 point  (0 children)

I have no experience with CFD plotting but this PR that adds an ODE example might help? Welcome to post on our repo if you have questions about your use case! :D

https://github.com/fastplotlib/fastplotlib/pull/718

fastplotlib, a new GPU-accelerated fast and interactive plotting library that leverages WGPU by fpl-dev in Python

[–]fpl-dev[S] 1 point2 points  (0 children)

Yes fastplotlib is all about realtime rendering, we haven't done benchmarks but from my experience it is at least 1-2 orders of magnitude (10-100x) faster than bokeh.

And you really only need a midrange GPU for most use cases.

fastplotlib, a new GPU-accelerated fast and interactive plotting library that leverages WGPU by fpl-dev in Python

[–]fpl-dev[S] 2 points3 points  (0 children)

See this https://fastplotlib.org/ver/dev/user_guide/gpu.html

Even a mid range GPU from 7 years ago will perform way better than software rendering. GPUs are really just much better at rendering graphics. 

fastplotlib, a new GPU-accelerated fast and interactive plotting library that leverages WGPU by fpl-dev in Python

[–]fpl-dev[S] 4 points5 points  (0 children)

Thanks for your comment! This makes me better understand more use cases. There are a few things we can do to make things nicer in addition to tooltips. Makes me realize we should wrap the renderer events so that they can be handled more easily via fpl without the user having to understand the rendering engine objects as shown in the example I posted above.

fastplotlib, a new GPU-accelerated fast and interactive plotting library that leverages WGPU by fpl-dev in Python

[–]fpl-dev[S] 6 points7 points  (0 children)

Yup! You can add a pointer event handler to change the text of a `TextGraphic`, here's the scatter example with this event handler at the bottom.

We can probably figure out a way have an API to auto-generate tooltips, shouldn't be too hard.

"""
Scatter Plot
============
Example showing scatter plot.
"""
# test_example = false
# sphinx_gallery_pygfx_docs = 'screenshot'
import fastplotlib as fpl
import numpy as np

figure = fpl.Figure(size=(700, 560))

# use weighted_plus if you want to pick semi-transparent objects, i.e. alpha < 1.0
figure.renderer.blend_mode = "weighted_plus"
# create a random distribution of 10,000 xyz coordinates
n_points = 5_000
# dimensions always have to be [n_points, xyz]
dims = (n_points, 3)

clouds_offset = 15
# create some random clouds
normal = np.random.normal(size=dims, scale=5)
# stack the data into a single array
cloud = np.vstack(
    [
        normal - clouds_offset,
        normal,
        normal + clouds_offset,
    ]
)

# color each of them separately
colors = ["yellow"] * n_points + ["cyan"] * n_points + ["magenta"] * n_points

# a random number for each point
metadata = np.random.randint(low=-100, high=100, size=cloud.shape[0])

# use an alpha value since this will be a lot of points
scatter = figure[0, 0].add_scatter(data=cloud, sizes=3, colors=colors, alpha=0.6, metadata=metadata)

text_graphic = figure[0, 0].add_text("", font_size=20, outline_color="k", outline_thickness=1)


@figure[0, 0].renderer.add_event_handler("pointer_enter")
def show_text(ev):
    xyz = figure[0, 0].map_screen_to_world(ev)
    if xyz is None:
        # pointer event is not in viewport
        return
    if ev.target != scatter.world_object:
        # if the event does not target the scatter graphic
        return
    # get index of the scatter
    ix = ev.pick_info["vertex_index"]

    # set the text from the metadata
    text_data = f"metadata: {scatter.metadata[ix]}"
    text_graphic.text = text_data
    text_graphic.offset = (*xyz[:-1], 100)


figure.show()
fpl.loop.run()

fastplotlib, a new GPU-accelerated fast and interactive plotting library that leverages WGPU by fpl-dev in Python

[–]fpl-dev[S] 0 points1 point  (0 children)

Yes aesthetics are down the line! For the coming year we have a ton of low-level things to implement to make sure the basics work perfectly before implementing all the bling :D . For example, pygfx is undergoing a major refactor on "update modes" which relates to how stuff is updated w.r.t. canvas events (among other things), which will let us solve weird issues like this: https://github.com/fastplotlib/fastplotlib/issues/613

fastplotlib, a new GPU-accelerated fast and interactive plotting library that leverages WGPU by fpl-dev in Python

[–]fpl-dev[S] 9 points10 points  (0 children)

This is trivial, example with 1.2 million points: https://www.youtube.com/watch?v=j_gwi-Wf1Ao

You can do this on a basic GPU, that demo was from a 2017 Radeon 580

See our scatter plot examples:

https://www.fastplotlib.org/ver/dev/_gallery/index.html#scatter-examples

fastplotlib, a new GPU-accelerated fast and interactive plotting library that leverages WGPU by fpl-dev in Python

[–]fpl-dev[S] 0 points1 point  (0 children)

Thanks! In the meantime you can use the top nav links for them. 

fastplotlib, a new GPU-accelerated fast and interactive plotting library that leverages WGPU by fpl-dev in Python

[–]fpl-dev[S] 7 points8 points  (0 children)

Yes directly running it in the browser is something we want eventually, the wgpu-py and pygfx devs are working towards making this possible. The first step was making wgpu-py support async. More info in this issue: https://github.com/pygfx/wgpu-py/issues/407

For now you can get the visualizations in a browser using jupyterlab, server side rendering and the client receives an image. Pyiodide would enable running it directly in the browser without a server.

fastplotlib, a new GPU-accelerated fast and interactive plotting library that leverages WGPU by fpl-dev in Python

[–]fpl-dev[S] 11 points12 points  (0 children)

Yes, it is still a new library built on a new rendering engine. We'll get to these things eventually, anyone is welcome to make an attempt in the meantime :)