After the deployment of streamlint cloud, the images drawn by matplotlib cannot be displayed in Chinese, but can be displayed when running locally

The prompt provided by streamlint cloud is:

findfont: Font family ['sans-serif'] not found. Falling back to DejaVu Sans.
findfont: Generic family 'sans-serif' not found because none of the following families were found: simhei
findfont: Font family ['sans-serif'] not found. Falling back to DejaVu Sans.
findfont: Generic family 'sans-serif' not found because none of the following families were found: simhei
How can I solve this?

在Ubuntu系统中,第一次利用Python进行机器学习或数值计算,当需要作图且图表的图例或坐标轴含有汉子时,一般会给出findfont: Font family [‘sans-serif’] not found的错误,原因是SimHei字体缺失。

解决的办法如下:下载Simhei字体。直接百度下载就行了,将下载下来的字体解压出来~~~

Local applications can be displayed. Fonts in Chinese cannot be displayed after deploying to the streamlit cloud.

因为streamlit cloud上的自带的字体中没有中文字体,所以matplotlib无法调用中文字体。

解决方案:
1、下载中文字体文件:SimHei.ttf
2、输入代码:
mpl.font_manager.fontManager.addfont(‘字体路径/SimHei.ttf’) #临时注册新的全局字体
plt.rcParams[‘font.sans-serif’]=[‘SimHei’] #用来正常显示中文标签
plt.rcParams[‘axes.unicode_minus’]=False#用来正常显示负号

3、登录streamlit cloud,选择app右边的下拉菜单–Reboot

Done!

Any more questions,you can send an e-mail to me.Welcome to talk. I’m a rookie, too
Mail address:hhiop@live.cn