这个问题类似于IPython Notebook中的内联自动运行%matplotlib内联,除了您要自动使用TK后端而不是内联后端。
因此,想法是找到您的IPython配置文件。请参阅配置IPython。它应该是
/.ipython/profile_default/ipython_kernel_config.py
如果尚不存在,请通过创建> ipython profile create
。
在此文件中找到设置c.InteractiveShellApp.matplotlib
并将其设置为"tk"
。然后应该看起来像
## Configure matplotlib for interactive use with the default matplotlib backend.
c.InteractiveShellApp.matplotlib = "tk"
保存文件并重新启动内核。