zoukankan      html  css  js  c++  java
  • Pandas matplotlib 无法显示中文 Ubuntu16.04

    版本

    Ubuntu16.04
    python3.6.2

    具体步骤

    1. 运行代码
    #!usr/bin/env python
    #-*- coding:utf-8 _*-
    """
    @author:fonttian
    @file: testCN.py
    @time: 2017/09/26
    """
    
    from matplotlib.font_manager import FontManager
    import subprocess
    
    fm = FontManager()
    mat_fonts = set(f.name for f in fm.ttflist)
    
    output = subprocess.check_output(
        'fc-list :lang=zh -f "%{family}
    "', shell=True)
    output = output.decode('utf-8')
    # print '*' * 10, '系统可用的中文字体', '*' * 10
    # print output
    zh_fonts = set(f.split(',', 1)[0] for f in output.split('
    '))
    available = mat_fonts & zh_fonts
    
    print('*' * 10, '可用的字体', '*' * 10)
    for f in available:
        print(f)
    
    import matplotlib
    
    print(matplotlib.matplotlib_fname())

    2.获取信息
    输出:

    ********** 可用的字体 **********
    Yahei Mono
    YaHei Consolas Hybrid
    /home/fonttian/anaconda3/lib/python3.6/site-packages/matplotlib/mpl-data/matplotlibrc

    前面的两个,是获取的可用字体,如果没有,需要自己下载.
    最后一行是需要修改的配置文件地址
    然后,删除文件中:删除font.family和font.sans-serif两行前的#,
    并在font.sans-serif后添加刚刚获取的中文字体

    3.删除~/.cache/matplotlib,(ctrl+H,显示隐藏文件)
    4.运行测试文件,本处给出一个测试文件

    import numpy as np
    import pylab as pl
    
    import matplotlib as mpl
    
    mpl.rcParams['font.sans-serif'] = ['Yahei Mono']
    mpl.rcParams['font.serif'] = ['Yahei Mono']
    t = np.arange(0.0,2.0 * np.pi,0.01) # 自变量取值范围
    s = np.sin(t) # 计算正弦函数值
    z = np.cos(t) # 计算余弦函数值
    pl.plot(t,s,label='正弦')
    pl.plot(t,z,label='余弦')
    pl.xlabel('x-变量') #设置标签
    pl.ylabel('y-正弦余弦函数值')
    pl.title('sin-cos函数图像') #图像标题
    pl.show()
    

    这里写图片描述

    5.pandas,方法一样,此处只给出一个结果
    这里写图片描述

    其他

    有参考:建议参考内容:https://www.zhihu.com/question/25404709
    win下:http://blog.csdn.net/fontthrone/article/details/75042659

  • 相关阅读:
    【Sharding-JDBC】配置手册
    【Sharding-JDBC】数据脱敏
    【Sharding-JDBC】分布式事务
    【Sharding-JDBC】编排治理
    【Sharding-JDBC】强制路由
    【Sharding-JDBC】不支持项
    【Sharding-JDBC】读写分离
    【Sharding-JDBC】数据分片
    apache commons configuration
    【Sharding-JDBC】简介
  • 原文地址:https://www.cnblogs.com/fonttian/p/9162772.html
Copyright © 2011-2022 走看看