← 返回首页
Plot frame by kushalkolar · Pull Request #313 · fastplotlib/fastplotlib · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

Plot frame#313

Merged
kushalkolar merged 22 commits into
mainfrom
plot-frame
Oct 31, 2023
Merged

Plot frame#313
kushalkolar merged 22 commits into
mainfrom
plot-frame

Conversation

kushalkolar commented Oct 3, 2023
edited
Loading

Copy link
Copy Markdown
Member

closes #310 closes #342 closes #268

This PR adds a Frame class that manages how plots are shown. Plot and Gridplot, and any future flexilbe gridplot, inherit from Frame.

How this works:

Toolbars

Refactored ipywidget Toolbar that is common between Plot, Gridplot and any future gridplots

Output Contexts

These are classes that "hold" the output of a Plot/Gridplot. They determine how the canvas, toolbar, and any additional widgets are shown. When Plot.show() is called, they return an instance of one of the following output contexts based on the curent plot canvas.

  • JupyterOutputContext
    • Inherits from ipywidgets.VBox and contains the canvas, toolbar, and any other widgets. Manages sidecar if desired.
  • QOutputContext
    • Inherits from QWidget, contains the canvas, qt toolbar, and any other widgets.
  • If the canvas is not jupyter or qt (ex. if it's glfw or offscreen like in our test suite), the output context is just the plot canvas itself.

This cleans up the messy show() calls we previously had everywhere, and cleans up other stuff too. Now the output context manages closing plots too.

BTW, the QOutputContext can also be used in notebooks with if you execute %gui qt before creating plots 😄

clewis7 commented Oct 3, 2023

Copy link
Copy Markdown
Member

#310

kushalkolar marked this pull request as ready for review October 29, 2023 20:48

Copy link
Copy Markdown
Member Author

This is working now with JupyterOutputContext! Also fixed the wonky issue with auto-scale and center scene when you had a single controller controlling multiple cameras for diff subplots.

Now onto Qt output context and toolbar.

Copy link
Copy Markdown
Member Author

Everything works on my end, I tested every combination with ipywidgets, sidecar/no sidecar, Qt, and with ImageWidget.

Right now the toolbar implementations are quite repetitive, we can make that nicer in a future PR after we have some time to think about it. Someone must have made a common interface between ipywidgets and Qt that we can use.

qt.mp4

Comment thread fastplotlib/layouts/_frame/_frame.py Show resolved Hide resolved
Comment thread fastplotlib/layouts/_frame/_frame.py Show resolved Hide resolved
Comment thread fastplotlib/layouts/_frame/_ipywidget_toolbar.py Outdated Show resolved Hide resolved
Comment thread fastplotlib/layouts/_frame/_ipywidget_toolbar.py Outdated Show resolved Hide resolved
self.output = (frame.canvas, *add_widgets)

if make_toolbar: # make toolbar and stack canvas, toolbar, add_widgets
self.toolbar = IpywidgetToolBar(frame)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

what if ImageWidget? where is logic for if plot type is imagewidget?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

ImageWidget just uses the Gridplot context:

def show(self, toolbar: bool = True, sidecar: bool = False, sidecar_kwargs: dict = None): """ Show the widget Returns ------- OutputContext """ if self.gridplot.canvas.__class__.__name__ == "JupyterWgpuCanvas": self._image_widget_toolbar = IpywidgetImageWidgetToolbar(self) elif self.gridplot.canvas.__class__.__name__ == "QWgpuCanvas": self._image_widget_toolbar = QToolbarImageWidget(self) return self.gridplot.show( toolbar=toolbar, sidecar=sidecar, sidecar_kwargs=sidecar_kwargs, add_widgets=[self._image_widget_toolbar] )

clewis7 commented Oct 30, 2023

Copy link
Copy Markdown
Member

did you update the requirements file?

clewis7 commented Oct 30, 2023

Copy link
Copy Markdown
Member

Another thing I see is that when I have two subplots in an imagewidget and the camera y_scales are opposite that when I change click between subplots the flip button is not changing in accordance with the camera y_scale...just stays the same

Copy link
Copy Markdown
Member Author

did you update the requirements file?

No dependency changes here.

Copy link
Copy Markdown
Member Author

Another thing I see is that when I have two subplots in an imagewidget and the camera y_scales are opposite that when I change click between subplots the flip button is not changing in accordance with the camera y_scale...just stays the same

In ipywidgets or Qt?

clewis7 commented Oct 30, 2023

Copy link
Copy Markdown
Member

Another thing I see is that when I have two subplots in an imagewidget and the camera y_scales are opposite that when I change click between subplots the flip button is not changing in accordance with the camera y_scale...just stays the same

In ipywidgets or Qt?

ipwidgets

clewis7 commented Oct 30, 2023

Copy link
Copy Markdown
Member

did you update the requirements file?

No dependency changes here.

not even if someone only wants qt? they would need to have pyqt6 installed right?

Copy link
Copy Markdown
Member Author

did you update the requirements file?

No dependency changes here.

not even if someone only wants qt? they would need to have pyqt6 installed right?

Qt land is a bit complicated, so they will have to install Qt themselves separately. We can do toggles later, because to do this properly we need to give users the option of PySide etc and decide how broad we want this support.

Copy link
Copy Markdown
Member Author

Another thing I see is that when I have two subplots in an imagewidget and the camera y_scales are opposite that when I change click between subplots the flip button is not changing in accordance with the camera y_scale...just stays the same

In ipywidgets or Qt?

ipwidgets

I think now I see what you mean, it is wonky! So this is because in ImageWidget all cameras are under one controller. I did not decide how to deal with flipping when controllers are diff. What I will do is if the flip button is clicked, it will flip the camera for the current subplot but also any camera that has the same controller (similar to what I did for panzoom and maintain_aspect).

kushalkolar merged commit 932454f into main Oct 31, 2023
kushalkolar mentioned this pull request Oct 31, 2023
kushalkolar deleted the plot-frame branch October 31, 2023 04:29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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 this pull request may close these issues.

make sidecar=False the default? make a PlotFrame class for Toolbar and sidecar functionality Setting the coordinate reference system

2 participants

Footer

© 2026 GitHub, Inc.