Skip to content

module reorganization #53

Closed
Closed

Description

@kushalkolar

Currently everything is basically imported at top level, it could get messy if we expand to include more widgets for example. Currently Image and ImageWidget exist.

Only the following should exist at the top level:

  • graphics
  • layouts
  • Plot
  • widgets

For quick simple plots they just use Plot(), for everything else they do something like:

from fastplotlib.graphics import Image, Line
from fastplotlib.layouts import GridPlot

# or for widget plots
from fastplotlib.widgets import ImageWidget

@EricThomson thoughts?

Activity

  1. kushalkolar commented on Dec 6, 2022

    @kushalkolar
    MemberAuthor

    I think we should try and minimize the number of imports that have to be written, try to avoid becoming messy like bokeh. Maybe have the widgets importable at top level since those will probably be used more frequently. Should see what we come up with for the events system as well in #39 and see where that will go.

  2. EricThomson commented on Dec 6, 2022

    @EricThomson
    Contributor

    This sounds like a good strategy to me! The one question I have here is where the line is between things that would fall into the Plot and graphics functionality. E.g., again with my usual thought: try to emulate matplotlib where it is strong, but break from it where it is not (and where people don't really use it much anyway).

    import fastplotlib.Plot as plot
    plot = Plot()
    plot.scatter() #does a scatter plot
    plot.plot()  # plots a line (don't make ppl think about what special objects are needed)
    plot.imshow()  # again, just let people do what they already expect
    

    But then for special widgets with a ui component, you need widgets because matplotlib is not great, so you have special things for that, because you don't want to emulate matplotlib.

    Anyway, just thinking out loud here as usual. I may well be wrong, esp as I am not yet a power user of fastplotlib.

  3. kushalkolar commented on Dec 6, 2022

    @kushalkolar
    MemberAuthor

    Kind of, this is how the simple plot functionality works:

    from fastplotlib import Plot()
    
    plot = Plot()  # create a plotter
    
    plot.image()  # image plot
    plot.line()  # line plot, put on the same canvas since we're using the same plot instance
    plot.scatter()  # scatter plot, put on top of the previous
    ... etc.

    It's similar to matplotlib but I think a bit more explicity, image, line, scatter are the same exact names as the Graphic classes. That's how it's actually implemented in the Plot class anyways and probably makes it easy for a user to go between the simple Plot interfaces and Graphics if necessary.

    For widgets, currently the image widget works like this:

    from fastplotlib.widgets import ImageWidget
    
    iw = ImageWidget(data=<data>, cmap="plasma")
    
    # if it's a single data array, they can access the `Plot` instance of the imagewidget and add more things
    iw.plot.line(data=<some line data>)
  4. EricThomson commented on Dec 16, 2022

    @EricThomson
    Contributor

    Just using with recent changes, it seems there are a lot of imports I'm doing right now, e.g.,:

    from fastplotlib import Plot
    from fastplotlib.layouts import GridPlot
    from fastplotlib.graphics import ImageGraphic
    

    This seems like too much for the simplicity of what I'm trying to do.

    I see the utility of having these layout/graphics things in separate modules, but I wonder if you might want to set up the package (with imports in __init__) so people can just from fastplotlib import Plot, GridPlot, Image and all the things, but also maybe more importantly for the future they can just import fastplotlib as fpl and then just use these different widgets as needed? grid_plot = fpl.GridPlot(...things..).

    FOr people that like to keep things logically ordered, they could still import as above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions