GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — API things, names, consistency, etc. · Issue #68 · fastplotlib/fastplotlib

API things, names, consistency, etc.  #68

New issue
Copy link
New issue
Copy link
Closed
Closed
API things, names, consistency, etc. #68
Copy link

Description

@kushalkolar
kushalkolar
opened on Dec 14, 2022
Issue body actions

currently the simple Plot API attaches methods like plot.image, plot.line etc which adds a graphic to the plot. This is kinda matplotlib inspired but could quickly get polluted (i.e. matlab inspired) . What if we prefix these methods with "add", so it becomes plot.add_image, plot.add_line etc. Because then I could also add add this behavior to the GridPlot API to remove the add_graphic step which is just boilerplate, while keeping the api clean. All add_ methods must add something to the plot or Subplot.

@EricThomson thoughts?

Activity

  1. EricThomson commented on Dec 14, 2022

    @EricThomson
    EricThomson
    on Dec 14, 2022
    Contributor
    More actions

    I definitely think it's a good idea to stick with one api either way. One of the most annoying things about matplotlib is the plt.title() vs ax.set_title() for pyplot vs object-oriented api (I realize not quite the same, but you know what I mean: it is basically an unnecessary barrier to entry).

    Not sure about which is the right move: I tend to want to type fewer words and stick with what people will tend to naturally just try, so like things like .scatter() over .add_scatter(), but honestly both would be good as long as consistent.

  2. kushalkolar commented on Dec 15, 2022

    @kushalkolar
    kushalkolar
    on Dec 15, 2022
    MemberAuthor
    More actions

    yes consistency between the Plot API and GridPlot API would be nice and reduce boilerplate for using the GridPlot which could be a barrier to entry.

    For example now we have:

    from fastplotlib.layouts import GridPlot
    from fastplotlib.graphics import ImageGraphic, LineGraphic
    
    gp = GridPlot((2, 3))
    
    img_graphic = ImageGraphic(data=....)
    gp[0, 0].add_graphic(img_graphic)
    
    line = LineGraphic(data=....)
    gp[0, 0].add_Graphic(line)

    This could be reduced to:

    from fastplotlib.layouts import GridPlot
    
    gp = GridPlot((2, 3))
    
    gp[0, 0].add_image(data=...)
    gp[0, 0].add_line(data=...)

    People can worry less about using Graphics objects directly unless they're doing something more complex.

    A Subplot in a GridPlot is almost the same as Plot. Plot is actually just a subclass of Subplot with a show() method so it can be shown by itself, and the graphic methods attached to it. https://github.com/kushalkolar/fastplotlib/blob/master/fastplotlib/plot.py#L10

  3. EricThomson commented on Dec 15, 2022

    @EricThomson
    EricThomson
    on Dec 15, 2022
    Contributor
    More actions

    Yes, that would be nice, I recently did the two-line approach when drawing contours on an image, and it seemed like too much. I was wondering why not gp[n,m].line()? Why is there the intermediate step of creating the line object and then adding it?

  4. kushalkolar commented on Dec 15, 2022

    @kushalkolar
    kushalkolar
    on Dec 15, 2022
    MemberAuthor
    More actions

    Why is there the intermediate step of creating the line object and then adding it?

    No reason really. Before I make this change we will just have to make sure it doesn't introduce annoying namespace pollution. For example we soon want to add Selector objects #59 , I can imagine the API for that being something like gp[m, n].add_selector_linear, add_selector_rectangle etc. I think it shouldn't get out of hand, I'm very much in favor of making this change.

  5. kushalkolar commented on Dec 15, 2022

    @kushalkolar
    kushalkolar
    on Dec 15, 2022
    MemberAuthor
    More actions

    I think this is what I'm going to do:

    Subplot gets all the add_<graphic>, add_selector_<type> methods attached to it, this allows them to be used without boilerplate in Plot and GridPlot.

    All other types of PlotArea, such as docked-subplots (see this: #30 (comment)), do not get these methods appended to them and must use the full API to add things to them for more complex plots.

  6. kushalkolar commented on Dec 17, 2022

    @kushalkolar
    kushalkolar
    on Dec 17, 2022
    MemberAuthor
    More actions

    so it's simplified now, leaving this open until we make the selectors

  7. kushalkolar commented on Dec 17, 2022

    @kushalkolar
    kushalkolar
    on Dec 17, 2022
    MemberAuthor
    More actions

    For z position, I think it'd useful to set the z position automatically if not provided so that whenever a new graphic is added it is by default above all existing graphics.

  8. EricThomson commented on Dec 20, 2022

    @EricThomson
    EricThomson
    on Dec 20, 2022
    Contributor
    More actions

    Note I've been working with this new api for a little bit now and really like it. I like not having to do this:

    Simply running add_line() is more intuitive and Pythonic in the long-run I think.

  9. kushalkolar
    pinned this issue on Dec 24, 2022
  10. kushalkolar
    unpinned this issue on Dec 24, 2022
  11. kushalkolar
    changed the title [-]simple Plot API[/-] [+]API things, names, consistency, etc. [/+] on Dec 30, 2022
  12. kushalkolar commented on Dec 30, 2022

    @kushalkolar
    kushalkolar
    on Dec 30, 2022
    MemberAuthor
    More actions

    The way that graphics are stored across objects in fastplotlib is inconsistent. For example in subplots/plots we have:

    plot.get_graphics()

    but in graphic collections we have:

    line_collection.items

    Maybe we should make it consistent, anywhere that an iterable of graphics is "stored" we just use a graphics read-only property? that would result in:

    plot.graphics  # gives tuples of graphics in the plot/subplot
    line_collection.graphics  # also gives tuple of graphics in the collection
  13. EricThomson commented on Jan 8, 2023

    @EricThomson
    EricThomson
    on Jan 8, 2023
    Contributor
    More actions

    I like the idea of making it consistent. I personally like things like .get_graphics()
    but consistency either way is good I think (I know in Python naming getters and setters as such is often frowned upon :) ).

  14. kushalkolar commented on Apr 18, 2023

    @kushalkolar
    kushalkolar
    on Apr 18, 2023
    MemberAuthor
    More actions

    Now that fully fledged selectors are coming in I think we've come to a good system. Selectors are added onto a graphic using graphic.add_<selector_name>. If users want to add more general selectors without a "parent" Graphic and get full control they can do that too by instantiating a Selector themselves and adding it to a PlotArea

  15. kushalkolar commented on Jun 22, 2023

    @kushalkolar
    kushalkolar
    on Jun 22, 2023
    MemberAuthor
    More actions

    We've been using this API for ~6 months now so I think we're pretty comfortable with it now. Whenever we have a hierarchy of objects, we just use Parent.add_<child_name>(). parent can be a PlotArea or Graphic, and children can be a Graphic or Selector

    I think we can discuss further API naming, consistencies etc. in future issues.

  16. kushalkolar
    closed this as completedon Jun 22, 2023
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

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.