具有非ASCII数据的matplotlib pyplot表? [英] matplotlib pyplot table with non-ascii data?

查看:135
本文介绍了具有非ASCII数据的matplotlib pyplot表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在png中创建一个表格。



表中的数据包含非ASCII字符(假设是中文或某事)



我通过unicode代码点(u'hello))来显示,它将字符显示为正方形。

解决方案

依赖于(略)平台,但我更喜欢使用 unicode 为中文和其他语言。另外一件事是你需要确保是 matplotlib 必须得到必要的字体。您可以在需要文本的任何地方执行,除非有时不在 mathtext 中。

 # -  *  - 编码:utf-8  -  *  -  
import matplotlib.pyplot as plt
import matplotlib
zhfont1 = matplotlib .font_manager.FontProperties(fname ='/ Library / Fonts / Kai.dfont')#我在OSX上。
s = u'\\\哈\\\哈'#需要你的中文字符的unicode。
plt.text(0.5,0.5,s,fontproperties = zhfont1,size = 50)#example:plt.text()


I'm trying to create a table figure in png.

The data in the table contains non-ascii characters.(suppose it's chinese or something)

I pass unicode code-points (u'hello') to pyplot and it shows the characters as squares.

解决方案

It may be (slightly) platform dependent, but I prefer to use unicode for Chinese and other languages. One other thing is that you need to make sure is matplotlib must get the necessary font. You can do it anywhere you need a text except sometimes not with mathtext.

# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
import matplotlib
zhfont1 = matplotlib.font_manager.FontProperties(fname='/Library/Fonts/Kai.dfont') #I am on OSX.
s=u'\u54c8\u54c8' #Need the unicode for your Chinese Char.
plt.text(0.5,0.5,s,fontproperties=zhfont1, size=50) #example: plt.text()

这篇关于具有非ASCII数据的matplotlib pyplot表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆