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

Line Plot Widget for sequential data #60

Open
zoccoler opened this issue Nov 1, 2022 · 8 comments
Open

Line Plot Widget for sequential data #60

zoccoler opened this issue Nov 1, 2022 · 8 comments
Labels
New feature New feature or request

Comments

@zoccoler
Copy link
Contributor

zoccoler commented Nov 1, 2022

Hi @dstansby , hi all,

I currently have a couple local implementations of a plotter with line plots based on metadata.
Data are stored in metadata because sometimes I generate data from intensity images which in napari, as far as I know, do not have 'properties' or 'features'.
I would like to have a general line plotter to import from. Thus, I naturally thought about napari-matplotlib!

To encompass all layer types, including the Image layer, I thought about storing the plotting data as a nested dictionary in the layer metadata, somtehing like:

{'plugin_name': 
    {'x_data': array},
    {'y_data': array},
    {'other_data': array} }`

I have some code that works with that kind of structure. Would that be an interesting contribution here?
From a plugin developer's perspective, storing data as a two level dictionary would allow filtering data origin (by 'plugin_name', so different plugins could fit) apart from regular image metadata and then axes would come from the internal keys. @kevinyamauchi , do you think such structure would be interesting?

Here is an example:
Capture

For example, for plotting a time series, a developer could include a time dimension array there as well.

If this should not belong here, that's also OK, I could place it somewhere else, just let me know ;)
I can make a Draft PR to further discuss this.

Best,
Marcelo

@Chris-N-K
Copy link
Contributor

@zoccoler if you want to plot images with a time dimension you could take a look at napari-time-series-plotter.
This widget uses napari-matplotlib as basis for its plotting and has multiple modes to visualise time series.

Just for transparency I'm the maintainer of napari-time-series-plotter.

@dstansby
Copy link
Member

Thanks for the suggestion, it sounds super interesting! I don't have time to properley think about this (but I didn't go immediately to no), but in the new year I will be working on napari-matplotlib with a CZI grant, so I will get back to you then - I hope that's okay! 😃

@dstansby dstansby added the New feature New feature or request label Nov 16, 2022
@zoccoler
Copy link
Contributor Author

Hi Christopher @ch-n, thanks for the hint! It seems you have quite some functionalities there for time-series! I am actually aiming in something more general, I mentioned time-series as a good example, but I would like to leave it to whatever array a developer would put in the layer metadata.

@dstansby congratulations for the grant!! That's totally fine, I put the code in this branch (https://github.com/zoccoler/napari-matplotlib/tree/line_plot_widget). I would PR to move discussion there if that's OK.

Looking forward for this functionality!

@dstansby
Copy link
Member

Hey @zoccoler I'm just looping back to this and wanted to understand use cases. There is currently a features scatter widget that can be used to scatter two features against each other. Would you like to have exactly the same functionality here, but with the points connected with a line?

@zoccoler
Copy link
Contributor Author

Overall, yes! I started around the layer metadata to be able to work with the Image layer, but as I mentioned in the PR just now I would be more interested in the features

@zoccoler zoccoler changed the title Line Plot Widget for metadata Line Plot Widget for sequential data Oct 25, 2023
@zoccoler
Copy link
Contributor Author

I just released a napari plugin which may better show where I would like to go with this: https://github.com/zoccoler/napari-signal-selector

Maybe a part of the code there could/should belong here.

@dstansby
Copy link
Member

I'm still slightly confused about #200, and have some suggestions that might help that I could add to that PR. However my intuition is that the widget in #200 is a bit more specialised than the other existing widgets, therefore I'm not 100% on whether it should go in.

Is all the functionality you want now implemented in https://github.com/zoccoler/napari-signal-selector? If so would you still like to push for #200 to go in napari-matplotlib or not? I'm happy to try and understand #200 a bit more and suggest improvements, but I'm not completely sold on it at the moment.

@zoccoler
Copy link
Contributor Author

Sure, let me try to explain my reasoning and you check what makes sense for napari-matplotlib or not.

  • LineBaseWidget would be a simple base class for drawing line plots, similar to what you have as ScatterBaseWidget but it employs .plot instead of .scatter or .hist2d to have Line2D artists.
  • FeaturesLineWidget would be similar to FeaturesScatterWidget with the difference that, since line plots better relate to ordered data, there is a need for a grouping part based on some object_id column (like in this line).

Both these classes I have put in my line.py file for now and those are the same suggested in #200. I thought they could belong here because they are basic line plots and IMO they differ from what you have in slice.py where you plot line profiles directly from the image.

Now, what I am bringing extra on my plugin is making these line plots interactive, basically creating a special Line2D class here and a derived widget class to have more methods and toolbuttons here, which allow selection and annotation of these lines.
The only "problem" is that eventually I had to overwrite the draw method to be able to store, keep track and update these new InteractiveLine2D instances (for example here) using axes.add_line here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New feature New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants