MacOs + Virtualenv + ipython notebook下使用matplotlib

来源:互联网 发布:淘宝直通车钱可以退吗 编辑:程序博客网 时间:2024/06/06 23:53

0.错误

在MacOs + Virtualenv + ipython notebook下使用matplotlib的时候会出现如下错误

**RuntimeError**: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends.

1.解决办法

修改matplotlib的backend,改成TkAgg

$ cd ~/.matplotlib$ vim matplotlibrc然后在文件里加入一行:backend: TkAgg

另一种方法是

import matplotlib as mptmpt.use('TkAgg')

参考:http://stackoverflow.com/questions/29433824/unable-to-import-matplotlib-pyplot-as-plt-in-virtualenv

2.在ipython notebook里面绘图

直接绘图会在弹出窗口里面绘图,在代码里加上

%matplotlib inline

3.最终

总的来说,按照如下方式import

import matplotlib as mplmpl.use('TkAgg')import matplotlib.pyplot as plt%matplotlib inline
0 0
原创粉丝点击