mac环境下pycharm关于matplotlib报错以及中文显示问题解决办法。

pycharm中matplotlib报错问题解决办法。

简单写个代码来看看报的错误

根据以上代码运行结果会报如下的错误:ImportError: 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. If you are using (Ana)Conda please install python.app and replace the use of 'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the Matplotlib FAQ for more information.

解决以上问题只需两行代码(只针对mac):

import matplotlib
matplotlib.use('TKAgg')

加上以上两行代码,结果将正常运行。

mac 彻底解决matplotlib中文乱码问题。

在我遇到中文乱码问题时,自己百度很多方法,按照步骤一步一步做,但还是没有成功。继续查看资料用了一个比较笨的方法解决掉了(方法虽笨,但能解决问题就行,特别是在快要绝望的时候)。

一、首先需要下载并且安装simhei字体(显示中文),直接百度下载就行。

二、找到你simhei.ttf文件的路径,然后将路径拷贝下来。

三、在你的python代码中添加下面内容,将拷贝的路径放在myfont = FontProperties(fname='/Users/leilei07/Downloads/simheittf-1/simhei.ttf') 中。

#解决中文显示问题
from matplotlib.font_manager import *
import matplotlib.pyplot as plt
#定义自定义字体,文件名从查看系统中文字体中来
myfont = FontProperties(fname='/Users/leilei07/Downloads/simheittf-1/simhei.ttf') 
#解决负号'-'显示为方块的问题
matplotlib.rcParams['axes.unicode_minus']=False

四、在你需要输出中文的地方,记得加上fontproperties=myfont就行了。

输出中文正常哦

以上!

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值