解决python画图标签中文乱码
来源:互联网 发布:数据库地址 编辑:程序博客网 时间:2024/05/16 18:52
在用python的时候经常会遇到乱码问题
1. 注释乱码问题
在代码的最上面添加:
# -*- coding: utf-8 -*-
2. 无法识别中文字体
通过运行以下代码查看系统中可以用的中文字体:
#! /usr/bin/env python# -*- coding: utf-8 -*-from matplotlib.font_manager import FontManagerimport subprocessfm = FontManager()mat_fonts = set(f.name for f in fm.ttflist)output = subprocess.check_output( 'fc-list :lang=zh -f "%{family}\n"', shell=True)# print '*' * 10, '系统可用的中文字体', '*' * 10# print outputzh_fonts = set(f.split(',', 1)[0] for f in output.split('\n'))available = mat_fonts & zh_fontsprint '*' * 10, '可用的字体', '*' * 10for f in available: print f
加入以下语句:
from pylab import *mpl.rcParams['font.sans-serif'] = ['Droid Sans Fallback']
注:Droid Sans Fallback 为查询得到的系统中的中文字体
3. 画图时候“-”号显示为方块问题
加入以下语句:
mpl.rcParams['axes.unicode_minus'] = False#解决保存图像是负号'-'显示为方块的问题
python 画图可以参考以下博客
http://www.cnblogs.com/wei-li/archive/2012/05/23/2506940.html#oo
http://old.sebug.net/paper/books/scipydoc/index.html#id2
0 0
- 解决python画图标签中文乱码
- rrdtool1.4.2画图中文乱码解决
- MATLAB画图中文乱码使用代码解决
- MAC 中python画图中文乱码
- python 中文乱码解决
- python中文乱码解决
- python解决中文乱码
- a标签中文乱码解决
- python MySQLdb中文乱码解决
- Python解决中文乱码问题
- 解决python输出中文乱码
- 解决python中文乱码问题
- Python中文处理-乱码解决
- Python解决中文乱码问题
- python shell 中文乱码解决
- Python解决中文乱码问题
- 【已解决】Matlab 画图输出 EPS 格式文件中文出现乱码
- Python3下使用matplotlib画图添加中文注释乱码解决
- scala学习之Map、Tuple、zip
- 第四届河南省程序设计大赛
- Codeforces Round #319 (Div. 2)E Points on Plane
- LeetCode:Letter Combinations of a Phone Number
- 调整基于HAAR特征的AdaBoost级联分类器的物体识别的参数
- 解决python画图标签中文乱码
- Android购物车初步实现2(功能篇)
- CentOS系统配置.ssh遇到port 22:No route to host问题的解决方法
- Android Agera 框架简单使用
- C++ vector 用法
- 21. Merge Two Sorted Lists(Linked List)
- 学生信息管理系统----错误集锦(一)
- Android学习系列(25)--App自动化之使用Ant编译项目多渠道打包
- fatal error C1001: INTERNAL COMPILER ERROR (compiler file 'msc1.cpp', line 1)记录