|
| 1 | +New parameter `clear` for :func:`~matplotlib.pyplot.figure` |
| 2 | +----------------------------------------------------------- |
| 3 | + |
| 4 | +When the pyplot's function :func:`~matplotlib.pyplot.figure` is called |
| 5 | +with a ``num`` parameter, a new window is only created if no existing |
| 6 | +window with the same value exists. A new bool parameter `clear` was |
| 7 | +added for explicitly clearing its existing contents. This is particularly |
| 8 | +useful when utilized in interactive sessions. Since |
| 9 | +:func:`~matplotlib.pyplot.subplots` also accepts keyword arguments |
| 10 | +from :func:`~matplotlib.pyplot.figure`, it can also be used there:: |
| 11 | + |
| 12 | + import matplotlib.pyplot as plt |
| 13 | + |
| 14 | + fig0 = plt.figure(num=1) |
| 15 | + fig0.suptitle("A fancy plot") |
| 16 | + print("fig0.texts: ", [t.get_text() for t in fig0.texts]) |
| 17 | + |
| 18 | + fig1 = plt.figure(num=1, clear=False) # do not clear contents of window |
| 19 | + fig1.text(0.5, 0.5, "Really fancy!") |
| 20 | + print("fig0 is fig1: ", fig0 is fig1) |
| 21 | + print("fig1.texts: ", [t.get_text() for t in fig1.texts]) |
| 22 | + |
| 23 | + fig2, ax2 = plt.subplots(2, 1, num=1, clear=True) # clear contents |
| 24 | + print("fig0 is fig2: ", fig0 is fig2) |
| 25 | + print("fig2.texts: ", [t.get_text() for t in fig2.texts]) |
| 26 | + |
| 27 | + # The output: |
| 28 | + # fig0.texts: ['A fancy plot'] |
| 29 | + # fig0 is fig1: True |
| 30 | + # fig1.texts: ['A fancy plot', 'Really fancy!'] |
| 31 | + # fig0 is fig2: True |
| 32 | + # fig2.texts: [] |
0 commit comments