Matplotlib及Seaborn中文显示问题
2019-03-30 19:40
525 查看
在使用matplotlib及seaborn时,中文无法正常显示,显示结果为一个方框,解决方法:
- Matplotlib
import numpy as np import matplotlib.pyplot as plt plt.rcParams['font.sans-serif'] = ['SimHei'] # 解决中文显示问题-设置字体为黑体 plt.rcParams['axes.unicode_minus'] = False # 解决保存图像是负号'-'显示为方块的问题 x = np.arange(-2*np.pi, 2*np.pi, 0.01) y1 = np.sin(x) y2 = np.cos(x) plt.figure(figsize=(10, 7)) plt.plot(x, y1, label='$sinx$') plt.plot(x, y2, label='$cosx$') plt.legend(loc='upper right') plt.xlim(-2*np.pi-1, 2*np.pi+3) plt.xticks([-2*np.pi, -np.pi, 0, np.pi, 2*np.pi], ['$-2\pi$', '$-\pi$', '$0$', '$\pi$', '$2\pi$']) plt.title('三角-函数') plt.xlabel('横坐标') plt.ylabel('纵坐标') plt.axhline(y=0, c='black') plt.show()
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- Seaborn
import numpy as np import matplotlib.pyplot as plt import seaborn as sns plt.rcParams['font.sans-serif'] = ['SimHei'] # 中文字体设置-黑体 plt.rcParams['axes.unicode_minus'] = False # 解决保存图像是负号'-'显示为方块的问题 sns.set(font='SimHei') # 解决Seaborn中文显示问题 x = np.arange(-2*np.pi, 2*np.pi, 0.01) y1 = np.sin(x) y2 = np.cos(x) plt.figure(figsize=(10, 7)) plt.plot(x, y1, label='$sinx$') plt.plot(x, y2, label='$cosx$') plt.legend(loc='upper right') plt.xlim(-2*np.pi-1, 2*np.pi+3) plt.xticks([-2*np.pi, -np.pi, 0, np.pi, 2*np.pi], ['$-2\pi$', '$-\pi$', '$0$', '$\pi$', '$2\pi$']) plt.title('三角-函数') plt.xlabel('横坐标') plt.ylabel('纵坐标') plt.axhline(y=0, c='black') plt.show()
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
相关文章推荐
- Matplotlib及Seaborn中文显示问题
- PyCharm seaborn matplotlib 显示中文问题
- Matplotlib输出中文显示问题
- Python matplotlib画图的中文显示问题
- 关于Mac系统下matplotlib中文显示方块问题
- python中matplotlib绘图中文显示问题
- 解决python27 matplotlib 中文不显示问题
- Mac系统彻底解决matplotlib中文显示乱码的问题
- python matplotlib中显示中文问题
- 解决Linux系统中python matplotlib画图的中文显示问题
- 解决matplotlib不能显示中文的问题(Ubuntu)
- matplotlib显示中文问题
- Matplotlib中文显示的问题
- Python中,matplotlib绘图无法显示中文的问题
- 解决python27 matplotlib 中文不显示问题
- matplotlib画图中文显示问题
- Matplotlib输出中文显示问题
- python中matplotlib绘图中文显示问题
- 解决matplotlib无法显示中文问题
- 解决python27 matplotlib 中文不显示问题