具体异常表现为
执行程序
import numpy as np
import matplotlib.pyplot as plt
X = np.linspace(-np.pi, np.pi, 256, endpoint=True)
C,S = np.cos(X), np.sin(X)
plt.plot(X,C)
plt.plot(X,S)
plt.show()
异常
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
解决方法:
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 is 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.
I resolve this issue following ways:
- I assume you have installed the pip matplotlib, there is a directory in you root called
~/.matplotlib. - Create a file
~/.matplotlib/matplotlibrcthere and add the following code:backend: TkAgg
From this link you can try different diagram.
在Mac OS环境下,使用PyCharm安装matplotlib后遇到绘图异常。问题在于matplotlib默认使用的Cocoa后端与其他操作系统不同。解决办法是设置matplotlib后端为macosx,创建~/.matplotlib/matplotlibrc文件并添加相应配置,确保图表正常显示。
1317

被折叠的 条评论
为什么被折叠?



