1

The following code works fine:

Python 3.8.2 (default, Apr  8 2020, 14:31:25) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
>>> fig = plt.figure()
>>> fig.suptitle("Empty figure")
Text(0.5, 0.98, 'Empty figure')
>>> fig.show()

But if I set subtitle (or do any other thing) after show, it will not work, even I run show() again.

Python 3.8.2 (default, Apr  8 2020, 14:31:25) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
>>> fig = plt.figure()
>>> fig.show()
>>> fig.suptitle("Empty figure")
Text(0.5, 0.98, 'Empty figure')
>>> fig.show()

I am new to python. Could anyone please help me?

2
  • Try removing the first instance >>>fig.show() Commented Apr 12, 2020 at 9:19
  • @enricw Yes, it will work after remove fig.show(). But I wonder how to update a shown figure. Commented Apr 12, 2020 at 9:25

1 Answer 1

1

In matplotlib, the .show() method by nature is designed to block any further execution of code after it is called until the shown figure is closed. Unless you turn on an interactive mode by calling .ion() before calling .show(), or there is an optional boolean parameter to be passed in to turn the blocking feature off as well:

plt.show(block=False)

Check out the documentation here: https://matplotlib.org/3.2.1/api/_as_gen/matplotlib.pyplot.show.html

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. Just run plt.ion() before show, everything works fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.