ENH: Allow to register standalone figures with pyplot · matplotlib/matplotlib@f97c262 · GitHub
Skip to content

Commit f97c262

Browse files
committed
ENH: Allow to register standalone figures with pyplot
It may be fundamentally nice not to have to create the figure though pyplot to be able to use it in pyplot afterwards. You can now do ``` from matplotlib.figure import Figure import matplotlib.pyplot as plt fig = Figure() fig.subplots().plot([1, 3, 2]) plt.figure(fig) # fig is now tracked in pyplot plt.show() ``` This also opens up the possibility to more dynamically track and untrack figures in pyplot, which opens up the road to optimized figure tracking in pyplot (#29849)
1 parent 77993d5 commit f97c262

3 files changed

Lines changed: 43 additions & 6 deletions

File tree

lib/matplotlib/pyplot.py

Lines changed: 19 additions & 4 deletions

lib/matplotlib/tests/test_figure.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,6 @@ def test_figure_label():
147147
assert plt.get_figlabels() == ['', 'today']
148148
plt.figure(fig_today)
149149
assert plt.gcf() == fig_today
150-
with pytest.raises(ValueError):
151-
plt.figure(Figure())
152150

153151

154152
def test_figure_label_replaced():

lib/matplotlib/tests/test_pyplot.py

Lines changed: 24 additions & 0 deletions

0 commit comments

Comments
 (0)