ubuntu16.04下使用matplotlib出现`TypeError: Couldn't find foreign struct converter for 'cairo.Context'`解决

在Ubuntu16.04环境下,使用Sublime Text3进行Python2编程时,遇到matplotlib运行错误`TypeError: Couldn't find foreign struct converter for 'cairo.Context'`。通过在.matplotlib目录下创建matplotlibrc文件并配置特定代码,成功解决问题,能够正常显示matplotlib图表。
摘要由CSDN通过智能技术生成

博主使用的时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()
时,遇到了以下问题:
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的文件夹,

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值