美文网首页
jupyter python seaborn画图时中文显示为框框

jupyter python seaborn画图时中文显示为框框

作者: 热苏斯 | 来源:发表于2019-11-22 17:40 被阅读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而不是服务

Restart the 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、运行,问题得到解决:

样图

相关文章

网友评论

      本文标题:jupyter python seaborn画图时中文显示为框框

      本文链接:https://www.haomeiwen.com/subject/hexqwctx.html