Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plot functionality #73

Closed
sharkdp opened this issue Feb 15, 2023 · 5 comments · Fixed by #464
Closed

Plot functionality #73

sharkdp opened this issue Feb 15, 2023 · 5 comments · Fixed by #464

Comments

@sharkdp
Copy link
Owner

sharkdp commented Feb 15, 2023

Combined with #51, this could be really powerful.

  • Evaluate functions at multiple points
  • Automatically label axes (x: input variable, input unit; y: function name, output unit)
@sharkdp sharkdp added this to the Feature parity milestone Feb 15, 2023
@sharkdp sharkdp removed this from the Feature parity milestone Mar 3, 2023
@sharkdp
Copy link
Owner Author

sharkdp commented Sep 11, 2023

A first prototype of this is available here: #147 #464

@irevoire
Copy link
Contributor

irevoire commented Aug 1, 2024

I recently played a lot with #73 and that is going to become so much faster.

About that I also played with it a little bit and implemented a version using egui
image

It comes with a native mode and a wasm mode which can run in a browser.

Pros:

  • It gives us great support for moving and zooming on the plot by supporting drag'n'drop + scrolling to zoom
  • Great support for tactile screen as well for phone and tablet
  • Since it's interactive, when you zoom-in it can requests more points and be more precise (This would require us to be able to execute numbat functions from rust)
We can create our own mark on charts and display stuff with the unit we want

Basically, egui let us write the mark we wants and spaces them however we want.
For example I played a bit with this functionality here: http://meteo.tamo.cool/
When I'm far away I only display the years:
image

Once I can decide to additionally display the month+year
image

And by zooming even more I start to display the hours:
image

With numbat in mind and #510 I can imagine a plot when the unit change while you zoom and that would be awesome.

Cons:

  • It doesn't generate HTML like plotly, which means it may not play well with the jupyter notebook you're trying to do? (I don't know anything about jupyter notebook)
  • The only way to save a graph on disk is to use the internal screenshot functionality, which I think requires us to open a window

Here's my branch where I only did the bare minimum: #516
If you're interested by this approach let me know and maybe I could help

@sharkdp
Copy link
Owner Author

sharkdp commented Aug 1, 2024

About that I also played with it a little bit and implemented a version using egui

Nice! I just played with it as well and looks great.

It gives us great support for moving and zooming on the plot by supporting drag'n'drop + scrolling to zoom

plotly can do this as well

Since it's interactive, when you zoom-in it can requests more points and be more precise (This would require us to be able to execute numbat functions from rust)

That would be really neat! But also.... difficult to implement, I think. Because we would need to run Numbat code from within a FFI function.

Basically, egui let us write the mark we wants and spaces them however we want.

👍

With numbat in mind and #510 I can imagine a plot when the unit change while you zoom and that would be awesome.

I agree


In general, I really like egui. I did a project with it in the past. I haven't looked closely into the plotting functionality, but I would be a bit hesitant to choose it over more "mature" plotting libraries. Maybe we're going to support different "backends" in the end. One for interactive viewing, one for generating high-quality images, one for the web? Ideally, that would all be supported by the same library, but I doubt that'll work.

Dependencies are also a concern. This is what I liked about the plotly option. It's rather lightweight since the heavy lifting is done by the JavaScript library that can be loaded in the browser, but doesn't need to be part of Numbat itself.

I think egui_plot is a really good contender in this space. Let's continue to do some experiments.


The biggest challenge right now for this feature is not the plotting backend, but rather the Numbat API that we'll use. Plotting "code" tends to have LOTS of configuration options. Even if we only support simple line and scatter plots, we're soon going to want to have more control over these plots (plot multiple functions, colors, line styles, axes options, linear vs logarithmic, …). And right now, I don't really have a good idea on how to design this in Numbat in its current stage. Maybe something like a huge struct of configuration options:

struct LinePlotOptions {
  label: String,
  log_x: Bool,
  log_y: Bool,
  line_style: String,
  line_color: Color,
  # …
}

and then something like

line_plot<X, Y>(fns: List<Fn[(X) -> Y]>, options: List<LinePlotOptions>)

Or maybe we would add the function itself to the options-struct as well.

But then we would need something like rusts ..default() construction or something like struct-update syntax.

As I said, I don't really have a great idea so far. Maybe the language is not yet ready for this.

@irevoire
Copy link
Contributor

irevoire commented Aug 2, 2024

As I said, I don't really have a great idea so far. Maybe the language is not yet ready for this.

It seems a bit early language-wise, but at the same time in terms of usage it could easily be a central part of numbat.
I feel like every single time I had to solve a problem that was more than 10 lines I wanted to plot some parts of it.

That would be really neat! But also.... difficult to implement, I think. Because we would need to run Numbat code from within a FFI function.

Yes I agree.
Being able to execute numba tcode from within a FFI function would be really neat to do some optimization (yeah I’m thinking about you map).

But then we would need something like rusts ..default() construction or something like struct-update syntax.

Either that or named optional parameter like they do in python.

It gives us great support for moving and zooming on the plot by supporting drag'n'drop + scrolling to zoom

plotly can do this as well

Nice, I missed that, I was struggling to move the chart but maybe I was just being dumb and didn't try to scroll to zoom.


Something else that would be nice with egui or anything that works interactively is that it would gives us the ability to define runtime parameters.
Like have a slider control a variable that will be given as an argument to your function.

@sharkdp
Copy link
Owner Author

sharkdp commented Aug 4, 2024

It seems a bit early language-wise, but at the same time in terms of usage it could easily be a central part of numbat.
I feel like every single time I had to solve a problem that was more than 10 lines I wanted to plot some parts of it.

Ok. Let's choose a good subset of features that we want for a first version of this. Maybe:

  • CLI version only
  • Line plots only, but plotting multiple functions at the same time should be possible
  • Configurability can be limited at the moment, but we should maybe have an idea how that could look like

@sharkdp sharkdp linked a pull request Aug 8, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants