matplotlib图例中文乱码解决

#! /usr/bin/env python
# -*- coding: utf-8 -*-
from matplotlib.font_manager  import FontManager
import subprocess
fm = FontManager()
mat_fonts = set(f.name for f in fm.ttflist)
#print(mat_fonts)
output = subprocess.check_output(‘fc-list :lang=zh -f "%{family}\n"‘, shell=True)
#print( ‘*‘ * 10, ‘系统可用的中文字体‘, ‘*‘ * 10)
#print (output)
zh_fonts = set(f.split(‘,‘, 1)[0] for f in output.decode(‘utf-8‘).split(‘\n‘))
available = mat_fonts & zh_fonts
print (‘*‘ * 10, u‘可用的字体‘, ‘*‘ * 10)
for f in available:  
    print (f)

修改你的matplotlib的配置文件matplotlibrc,

anaconda3/lib/python3.5/site-packages/matplotlib/mpl-data/matplotlibrc

这一部分,将#font.family : sans-serif 修改为 
font.family :  ‘Droid Sans Fallback‘
时间: 2024-08-10 02:08:58

matplotlib图例中文乱码解决的相关文章

Ubuntu环境下 matplotlib 图例中文乱码

本文前提条件是 已经 安装好 matplotlib  ,  至于 matplotlib 是什么, 怎么安装, 本文不予介绍. 首先在  Windows  盘区下  找到   微软雅黑   的字体文件: 其次,找到 matplotlab  字体库  文件夹    或者   系统字体库文件夹 matplotlab  字体库  文件夹 系统字体库文件夹 把字体文件拷贝到这两个路径下的任何一个都可以. 然后,找到 matplotlib  配置文件 可以直接修改该文件,或者 然后,  修改配置文件. 编辑

cocos2d-x 3.4 中文乱码解决之道

cocos2dx 中文乱码解决之道 需要引入五个文件 1.iconv.h 2.iconvString.cpp 3.iconvString.h 4.iconv.dll 5.libiconv.lib 完整下载地址http://download.csdn.net/detail/dao_1990/8935089 iconv.h /* Copyright (C) 1999-2003 Free Software Foundation, Inc. This file is part of the GNU LI

Jsp---cookie中文乱码解决方法

//写cookie <form method="Get"> 姓名: <input type="text" name="name" /> <br /> <input type="submit" value="确定" /> </form> <!-- 写入cookie到客户端 --> <% if (request.getParamete

win7下zend studio5.5中文乱码解决方法

win7下zend studio5.5中文乱码解决方法 1.打开 C:Documents and SettingsAdministratorZDEconfig_5.5desktop_options.xml(这个地址要根据自己的电脑而定.) 2.查找 editing.encoding 3.修改里面为 <encoding name=”UTF-8″/> 4.保存,并将该文件属性设置为只读,否则zend每次启动都会将 desktop_options.xml 初始化 5.重启 zend 注意,你现在打开

SpringMVC中使用@ResponseBody注解返回值,Ajax取得中文乱码解决方法

Spring使用AnnotationMethodHandlerAdapter的handleResponseBody方法, AnnotationMethodHandlerAdapter使用request header中"Accept"的值和messageConverter支持的MediaType进行匹配,然后会用"Accept"的第一个值写入 response的"Content-Type".一般的请求都是通过浏览器进行的,request heade

PHP中文乱码解决办法

一.         首先是PHP网页的编码 1.     php文件本身的编码与网页的编码应匹配 a.     如果欲使用gb2312编码,那么php要输出头:header("Content-Type: text/html; charset=gb2312"),静态页面添加<meta http-equiv="Content-Type" content="text/html; charset=gb2312">,所有文件的编码格式为ANS

玩转web之ajax(一)---使用表单的serialize()方法中文乱码解决

有时候我们需要使用ajax提交去提交form的值,这样就需要使用serialize()去获取form的值,但这样获取的值如果有中文,会乱码,原因和解决方法如下: 原因:.serialize()自动调用了encodeURIComponent方法将数据编码了 解决方法:调用decodeURIComponent(XXX,true);将数据解码 如: var data=$('#addf').serialize(); data= decodeURIComponent(data,true); 玩转web之a

PHP json_encode中文乱码解决方法

<?php /** * [PHP json_encode中文乱码解决方法] * 这里说的"中文乱码"其实不是不是真的乱码,而是在最后的json结果中显示下面的字串: * {"name":"\u4e2d\u6587\u5b57\u7b26\u4e32″,"value":"test"} * * [解决办法] * 在使用json_encode之前把字符用函数urlencode()处理一下,然后再json_encode

java中文乱码解决方法汇总

publicstaticvoidmain(String[]argv){ try{ System.out.println("中文");//1 System.out.println("中文".getBytes());//2 System.out.println("中文".getBytes("GB2312″));//3 System.out.println("中文".getBytes("ISO8859_1″));