ubuntu16.04下使用matplotlib出现`TypeError: Couldn't find foreign struct converter for 'cairo.Context'`解决
2017-10-23 20:05
871 查看
博主使用的时ubuntu16.04下的sublime text3配置python2运行环境,已经成功安装numpy,scipy,matplotlib环境,在测试代码
`import numpy as np
from scipy.stats import beta
from matplotlib.pyplot import hist, plot, show
obs = beta.rvs(5, 5, size=2000) # 2000 observations
hist(obs, bins=40, normed=True)
grid = np.linspace(0.01, 0.99, 100)
plot(grid, beta.pdf(grid, 5, 5), ‘k-‘, linewidth=2)
show()
并且弹出来一个空白的figure图框
经过’呕心沥血’的探索,终于找到了解决方案:
I assume you have installed the pip matplotlib, there is a directory in you root called ~ /. matplotlib. Create a file called matplotlibrc there and following code
就是你先进入你的home目录,按ctrl+h显示所有隐藏文件夹,找到一个叫matplotlib的文件夹,在里面创建一个叫做matplotlibrc的文件,在文件里输入以下代码
关闭并保存文件,把代码中的目录改成你电脑上matplotlib文件夹所在的目录。例如我的matplotlib文件夹路径是”~ / .config / matplotlib / “
我的matplotlibrc文件中代码就是
<注意>:我的代码没有写错,Matplotlibrc的m就是大写。
这种方法在python3中应该也适用(欢迎道友测试)。
最后在sublime text3输入测试代码,图标出来了:
Perfect!
`import numpy as np
from scipy.stats import beta
from matplotlib.pyplot import hist, plot, show
obs = beta.rvs(5, 5, size=2000) # 2000 observations
hist(obs, bins=40, normed=True)
grid = np.linspace(0.01, 0.99, 100)
plot(grid, beta.pdf(grid, 5, 5), ‘k-‘, linewidth=2)
show()
时,遇到了以下问题:TypeError: Couldn’t find foreign struct converter for ‘cairo.Context’`
并且弹出来一个空白的figure图框
经过’呕心沥血’的探索,终于找到了解决方案:
I assume you have installed the pip matplotlib, there is a directory in you root called ~ /. matplotlib. Create a file called matplotlibrc there and following code
~ / .matplotlib / Matplotlibrc backend: TkAgg
就是你先进入你的home目录,按ctrl+h显示所有隐藏文件夹,找到一个叫matplotlib的文件夹,在里面创建一个叫做matplotlibrc的文件,在文件里输入以下代码
~ / .matplotlib / Matplotlibrc backend: TkAgg
关闭并保存文件,把代码中的目录改成你电脑上matplotlib文件夹所在的目录。例如我的matplotlib文件夹路径是”~ / .config / matplotlib / “
我的matplotlibrc文件中代码就是
~ / .config / matplotlib / Matplotlibrc backend: TkAgg
<注意>:我的代码没有写错,Matplotlibrc的m就是大写。
这种方法在python3中应该也适用(欢迎道友测试)。
最后在sublime text3输入测试代码,图标出来了:
Perfect!
相关文章推荐
- anaconda 使用matplotlib画图出现 could not find or load Qt platform plugin "" 解决
- ubuntu 16.04下mysql5.7.17登录时出现ERROR 1045 (28000): Access denied for user 'root'@'localhost' 问题解决!
- 解决python中使用matplotlib时候出现ImportError: No module named _tkinter
- Jni使用过程中出现 error: request for member 'FindClass' in something not a structure or union,解决办法
- 关于使用pyinstaller 打包带有matplotlib 等出现UnicodeDecodeError解决方法
- python3使用matplotlib出现ImportError: No module named '_tkinter' 详细解决方法
- 关于使用pyinstaller 打包带有matplotlib 等出现UnicodeDecodeError解决方法
- 在使用matplotlib时报错_tkinter.TclError: couldn't connect to display ":0.0"
- 解决在jupyter notebook中遇到的ImportError: matplotlib is required for plotting问题
- ubuntu 下在 matplotlib 中正常显示中文的解决办法
- ubuntu 14.04使用root登陆出现错误“Error found when loading /root/.profile”解决
- ubuntu 下NetworkX,matplotlib的安装和使用(转)
- [完]Python 安装setuptools,解决使用Matplotlib遇到的问题
- 解决 在Ubuntu上执行 $adb shell 出现 error:insufficient permissions for device 问题
- 编译Android系统AIDL模块出现couldn't find import for class错误的解决办法
- ubuntu出现ERROR: Could not find 'wxe_driver.so' in: /usr/local/bin/erlang/lib/wx-1.2/priv
- python使用matplotlib缺少库文件的解决方法
- 使用Gevent程序正常运行出现这个异常KeyError(155880780,) in <module 'threading' from '/usr/lib/python2.7/threading.pyc'> ignored解决办法
- sql server 2000安装中出现:command line option syntax error,type command/? for help解决方法(转)
- matplotlib 使用时遇到的错误:ImportError: No module named six