jupyter python seaborn画图时中文显示为框框
2019-11-22 本文已影响0人
热苏斯
一、画的图中文刻度显示失败:

二、解决方式:
1、下载simhei.ttf文件,simhei.ttf下载链接
2、把simhei.ttf拷贝到/usr/local/anaconda3/lib/python3.7/site-packages/matplotlib/mpl-data/fonts/ttf/目录下
3、删除/root/.cache/matplotlib/, 或者改名也可以mv /root/.cache/matplotlib /root/.cache/matplotlib.bak
4、重启jupyter notebook的kernel,注意只需要重启该notebook的kernel而不是服务

5、添加声明代码块:
import pymongo
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings('ignore')
%matplotlib inline
%config ZMQInteractiveShell.ast_node_interactivity='all'
# plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['font.sans-serif'] = ['simhei'] # 中文字体设置-黑体
plt.rcParams['axes.unicode_minus'] = False # 解决保存图像是负号'-'显示为方块的问题
sns.set(font='simhei') # 解决Seaborn中文显示问题
6、运行,问题得到解决:
