-
Notifications
You must be signed in to change notification settings - Fork 5
DOC: add the API notes from Matplotlib discussion #21
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
Open
jklymak
wants to merge
2
commits into
matplotlib:main
Choose a base branch
from
jklymak:doc-notes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# API design notes | ||
|
||
## Current state | ||
|
||
### `fig, ax = plt.subplots() # and friends` | ||
|
||
- To show during interactive use or in a script: `plt.show()` will show all figures that have been created by pyplot that have note been `plt.close()`d. | ||
- `plt.show(block=False)` will show the current figure, but continue the script. | ||
- works with `inline` | ||
- works with ipympl | ||
|
||
#### Pros: | ||
|
||
- easy to show all plots. | ||
|
||
#### Cons: | ||
|
||
- mixed in with rest of `pyplot` | ||
- too many figures open; must manually close the ones we don't want anymore or memory grows. For a large jupyter notebook with cells executed many times, this can actually be substantial. | ||
|
||
### `fig = matplotlib.figure.Figure()` | ||
|
||
- cannot do `fig.show()`, but can do `fig.savefig()` | ||
- does not display anything in either `inline` or `ipympl` | ||
|
||
### Pros: | ||
|
||
- `fig` will be garbage collected because there are no references stored in a registry | ||
|
||
### Cons: | ||
|
||
- no way to show the figure on a GUI backend (no promotion possible). | ||
- ugly import. | ||
|
||
## Proposed changes | ||
|
||
### `mpl_gui` | ||
|
||
- `import matplotlib.mpl_gui as mg; fig, ax = mg.subplots()` | ||
- Can be shown, but with new `mg.show([fig])` (though singleton fig could trivially be added). | ||
- jupyter: works without `show` in `ipympl`; does _not_ (currently) work (at all) with `inline`. | ||
|
||
#### Pros: | ||
|
||
- no global state - garbage collection on dereferenced figures | ||
- no connection to pyplot state-based interface | ||
|
||
#### Cons: | ||
|
||
- New import and documentation (inertia relative to pyplot) | ||
- `mg.show()` doesn't know what figures to show, so it must be supplied a list of figures. | ||
- sometimes we create figures in loops, and assigning a different variable name to each figure to stop if from being dereferenced could be cumbersome. | ||
|
||
### `mpl_gui.registry` | ||
|
||
- `import matplotlib.mpl_gui.registry as mr; fig, ax = mr.subplots()` | ||
- allows `mr.show()` to be exactly the same as `plt.show`. | ||
|
||
#### Pros: | ||
|
||
- no connection to pyplot state-based interface | ||
- exactly same as previous pyplot interface for this type of work. | ||
|
||
#### Cons: | ||
|
||
- figures must be explicitly closed | ||
|
||
### `mpl_gui.FigureContext` | ||
|
||
This is between the two extremes, where there is no global registry, but a registry is maintained for a series of plots within a context: | ||
|
||
``` | ||
with mg.FigureContext() as fc: | ||
fig, ax = fc.subplots() | ||
fig, ax = fc.subplot_mosaic('AA\nBC') | ||
fig = fc.figure | ||
``` | ||
|
||
makes three figures and shows them in a blocking manner, and then removes the registry on completion. | ||
|
||
### Top-level import? | ||
|
||
The question arose as to whether these should be top level imports eg `fig, ax = mpl.subplots()` A choice would need to be made as to whether that is the registry or non-registry version of the new interface. |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
api | ||
release_history | ||
min_versions | ||
Api_Notes | ||
|
||
|
||
Motivation | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ mpl-sphinx-theme~=3.9.0 | |
numpydoc | ||
sphinx | ||
sphinx-copybutton | ||
myst-parser |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.