In [7]:
# matplotlib中文乱码
# import matplotlib.pyplot as plt
# myfont = matplotlib.font_manager.FontProperties(fname=r"c:\windows\fonts\simsun.ttc", size=14)
# https://segmentfault.com/a/1190000005144275

import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties

myfont = FontProperties(fname='C:/Windows/Fonts/MSYH.TTC')

plt.plot((1,2,3,-2),(4,3,-1,-3))
plt.xlabel(u'-横坐标',fontproperties=myfont)
plt.ylabel(u'-纵坐标',fontproperties=myfont)
plt.show()



In [8]:
# 为list等添加序号
fList=['a','b','c']
for i,f in enumerate(fList):
    print i,f


0 a
1 b
2 c

In [9]:
#python 字符编码与解码——unicode、str和中文:UnicodeDecodeError: 'ascii' codec can't decode
#http://blog.csdn.net/trochiluses/article/details/16825269
#在python中,编码:unicode-->str;解码str-->unicode
#str.encode()实际上就等价于str.decode(sys.defaultencoding).encode()

#!/usr/bin/python  
#coding=gbk  
string='我的'  
print string  
s1=unicode(string,"gbk")  
s2=string.decode("gbk")  
print s1  
print s2


我的
鎴戠殑
鎴戠殑