Use %matplotlib inline in spyder

When writing a python program in spyer, if you encounter %matplotlib inline, it will prompt invalid syntax, but it can be used normally in jupyter notebook.

Through online inquiry, I probably know what the reason is, and record it:

The purpose of %matplotlib inline is to draw graphics inline, not a pop-up window. It is not a python statement and needs to be entered and executed in the console.

If you want to switch between inline and pop-up windows to draw graphics in spyder, you can modify Graphics Backend under the menu Tools->Preferences->Ipython Console, Graphics tab. But this setting does not allow the program to switch by itself when the python program is running. If you want to switch while running the program, you need to use the following python statement (not verified):

from IPython import get_ipython
get_ipython().run_line_magic('matplotlib', 'inline')

reference:

https://www.cnpython.com/qa/537113

https://stackoverflow.com/a/46360516/789215

https://zhidao.baidu.com/question/1244676718439126979.html

Guess you like

Origin blog.csdn.net/eidolon_foot/article/details/113811764