pandas 作图无法显示中文
来源:互联网 发布:戴森无叶风扇 知乎 编辑:程序博客网 时间:2024/04/30 15:41
最近开始使用 pandas 处理可视化数据,挖掘信息。但是在作图时遇到,无法显示中文的问题。
下面这段代码是统计 fujian1.csv
文件中 City
所在列中各个城市出现次数的代码。可是作图直方图时在 x 轴上无法显示中文。
import pandas as pd# Reading data locallydf = pd.read_csv('fujian1.csv', encoding='gbk')counts = df['City'].value_counts()counts[counts > 1000].plot(kind = 'bar')
查了一些资料,找到的原因是 matplotlib 包默认只支持 ASCII 码,不支持 unicode 码。
解决方法,就是需要将 matplotlib
的安装目录下的 matplotlibrc
配置文件修改一下,将font.family
部分(大概在139行左右)注释去掉,并且在 font.serif
和 font.sans-serif
支持字体加上一个中文字体,如 SimHei:
font.family : sans-serif#font.style : normal#font.variant : normal#font.weight : medium#font.stretch : normal# note that font.size controls default text sizes. To configure# special text sizes tick labels, axes, labels, title, etc, see the rc# settings for axes and ticks. Special text sizes can be defined# relative to font.size, using the following values: xx-small, x-small,# small, medium, large, x-large, xx-large, larger, or smaller#font.size : 12.0font.serif : SimHei, Bitstream Vera Serif, New Century Schoolbook, Century Schoolbook L, Utopia, ITC Bookman, Bookman, Nimbus Roman No9 L, Times New Roman, Times, Palatino, Charter, seriffont.sans-serif : SimHei, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif#font.cursive : Apple Chancery, Textile, Zapf Chancery, Sand, cursive#font.fantasy : Comic Sans MS, Chicago, Charcoal, Impact, Western, fantasy#font.monospace : Bitstream Vera Sans Mono, Andale Mono, Nimbus Mono L, Courier New, Courier, Fixed, Terminal, monospace
最终实现了正常显示中文。
0 0
- pandas 作图无法显示中文
- Matplotlib 作图中文无法显示
- Pandas matplotlib 无法显示中文
- Pandas matplotlib 无法显示中文 Ubuntu16.04
- R语言作图保存在pdf中时无法显示中文标题
- 用Pandas作图
- 用Pandas作图
- 使用Python pandas作图
- 利用pandas高维作图
- 用python-pandas作图矩阵
- 用python-pandas作图矩阵
- 用python-pandas作图矩阵
- pandas 做图显示中文标签
- Flex无法显示中文
- mysql中文无法显示
- 中文无法显示
- VS2010 无法显示中文
- Haroopad中文无法显示
- HDU 1002
- Java内存模型
- NOJ -1007 完美立方
- 归并排序
- Eclipse下OpenFire4.0.2源码配置+简单插件开发
- pandas 作图无法显示中文
- NOJ - 1009 2的N次方
- 屏幕分辨率等级
- 单链表C/C++实现
- PHP中的流程控制
- 优秀开源项目SwipeLayout的使用
- NOJ - 2070 马尔扎哈的疑惑
- HTML5书写规范
- 关于“幽灵架构”的补充说明3:为什么不会产生“循环引用”