matplotlib Python 的安装问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/21784641/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Installation Issue with matplotlib Python
提问by J4cK
I have issue after installing the matplotlibpackage unable to import matplotlib.pyplot as plt. Any suggestion will be greatly appreciate.
安装matplotlib包后出现问题,无法将 matplotlib.pyplot 作为 plt 导入。任何建议将不胜感激。
>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "//anaconda/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-macosx-10.5-x86_64.egg/matplotlib/pyplot.py", line 98, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "//anaconda/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-macosx-10.5-x86_64.egg/matplotlib/backends/__init__.py", line 28, in pylab_setup
    globals(),locals(),[backend_name],0)
  File "//anaconda/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-macosx-10.5-x86_64.egg/matplotlib/backends/backend_macosx.py", line 21, in <module>
    from matplotlib.backends import _macosx
**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.
采纳答案by J4cK
Problem Cause
问题原因
In mac os image rendering back end of matplotlib (what-is-a-backend to render using the API of Cocoa by default). There are Qt4Agg and GTKAgg and as a back-end is not the default. Set the back end of macosx that is differ compare with other windows or linux os.
在 matplotlib 的 mac os 图像渲染后端(默认情况下使用 Cocoa 的 API 进行渲染的后端是什么)。有 Qt4Agg 和 GTKAgg 并且作为后端不是默认的。设置与其他windows或linux os不同的macosx后端。
Solution
解决方案
- I assume you have installed the pip matplotlib, there is a directory in your root called ~/.matplotlib.
- Create a file ~/.matplotlib/matplotlibrcthere and add the following code:backend: TkAgg
- 我假设您已经安装了 pip matplotlib,您的根目录中有一个名为~/.matplotlib.
- 在~/.matplotlib/matplotlibrc那里创建一个文件并添加以下代码:backend: TkAgg
From this linkyou can try different diagrams.
从这个链接你可以尝试不同的图表。

