plt.title()中文无法显示的问题解决
作者:臭皮匠-hfW 时间:2023-07-24 06:05:33
问题描述
由于画图时plt.title()默认是显示英文,如果我们设置标题为中文,会无法显示,如图:
plt.title('训练损失')
plt.plot(np.arange(len(losses)), losses, '-o', color='red')
plt.show()
解决办法
在画图前加入两行代码:
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
plt.title('训练损失')
plt.plot(np.arange(len(losses)), losses, '-o', color='red')
plt.show()
plt.title()函数参数说明
fontsize设置字体大小,默认12,可选参数 [‘xx-small’, ‘x-small’, ‘small’, ‘medium’, ‘large’,‘x-large’, ‘xx-large’]
fontweight设置字体粗细,可选参数 [‘light’, ‘normal’, ‘medium’, ‘semibold’, ‘bold’, ‘heavy’, ‘black’]
fontstyle设置字体类型,可选参数[ ‘normal’ | ‘italic’ | ‘oblique’ ],italic斜体,oblique倾斜
verticalalignment设置水平对齐方式 ,可选参数 : ‘center’ , ‘top’ , ‘bottom’ , ‘baseline’
horizontalalignment设置垂直对齐方式,可选参数:left,right,center
rotation(旋转角度)可选参数为:vertical,horizontal 也可以为数字
alpha透明度,参数值0至1之间
backgroundcolor标题背景颜色
bbox给标题增加外框 ,常用参数如下:
boxstyle方框外形
facecolor(简写fc)背景颜色
edgecolor(简写ec)边框线条颜色
edgewidth边框线条大小
来源:https://blog.csdn.net/weixin_45080292/article/details/130304191
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
PHP微信支付实例解析
python基本语法练习实例
python游戏测试工具自动化遍历游戏中所有关卡
![](https://img.aspxhome.com/file/2023/9/93589_0s.png)
python字典多键值及重复键值的使用方法(详解)
![](https://img.aspxhome.com/file/2023/3/131683_0s.jpg)
python 查找文件名包含指定字符串的方法
![](https://img.aspxhome.com/file/2023/5/127815_0s.jpg)
python如何调用字典的key
pytorch 可视化feature map的示例代码
Js过滤空格的实现代码
如何做一个可以让人家申请使用的计数器?
mysql去重查询的三种方法小结
![](https://img.aspxhome.com/file/2023/1/112631_0s.jpg)
numpy 声明空数组详解
Mysql| 使用通配符进行模糊查询详解(like,%,_)
Python如何将图像音视频等资源文件隐藏在代码中(小技巧)
SQL Server误区30日谈 第16天 数据的损坏和修复
Python实例练习逆序输出字符串讲解
![](https://img.aspxhome.com/file/2023/4/131234_0s.png)
Oracle 子程序参数模式,IN,OUT,NOCOPY
python 读取.csv文件数据到数组(矩阵)的实例讲解
python自然语言处理之字典树知识总结
![](https://img.aspxhome.com/file/2023/1/72811_0s.png)