V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
wisefree
V2EX  ›  Python

matplotlib 如何解决中英混排

  •  
  •   wisefree · 2016-11-02 11:42:08 +08:00 · 2444 次点击
    这是一个创建于 2733 天前的主题,其中的信息可能已经有所发展或是发生改变。
    请教大家一个问题,困扰我好几天了,:)
    matplotlib 中文显示不出来,修改了 matplotlibrc 文件,将字体改成了宋体。修改后生成的图片,中文和英文都是宋体,这样就很不美观,能够设置中文为宋体,英文为 Times New Roman 呢?
    有没有参考的思路呢?
    4 条回复    2016-11-02 18:12:31 +08:00
    justou
        1
    justou  
       2016-11-02 12:45:21 +08:00   ❤️ 3
    这样的?


    # -*- coding: utf-8 -*-
    import matplotlib.pyplot as plt
    from matplotlib.font_manager import FontProperties

    song_ti = FontProperties(fname=r'C:\Windows\Fonts\simsun.ttc', size=20)
    times_new_roman = FontProperties(fname=r'C:\Windows\Fonts\times.ttf', size=15)
    ax = plt.gca()
    ax.set_title(u'能量随时间的变化', fontproperties=song_ti)
    ax.set_xlabel('Time (s)', fontproperties=times_new_roman)
    ax.set_ylabel('Energy (J)', fontproperties=times_new_roman)
    plt.show()
    wisefree
        2
    wisefree  
    OP
       2016-11-02 16:39:52 +08:00
    @justou 如何得到 fonts 对应的文件名呢? simusun.ttc 在 fonts 文件夹下看不到
    网上搜索了一下,请问用 python 能实现么?
    justou
        3
    justou  
       2016-11-02 16:55:30 +08:00   ❤️ 1
    C:\Windows\Fonts 文件夹下右键看属性, 没有属性的是字体系列, 双击打开它看里面每个字体文件的属性, 里面有该字体的名字。
    wisefree
        4
    wisefree  
    OP
       2016-11-02 18:12:31 +08:00
    @justou 网上搜的结果,全部没有这个方法方便,谢谢啦:)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2900 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 08:56 · PVG 16:56 · LAX 01:56 · JFK 04:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.