欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

plt.title()中文無法顯示的問題解決

 更新時間:2023年04月26日 10:27:52   作者:臭皮匠-hfW  
本文主要介紹了plt.title()中文無法顯示的問題解決,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

問題描述

由于畫圖時plt.title()默認(rèn)是顯示英文,如果我們設(shè)置標(biāo)題為中文,會無法顯示,如圖:

plt.title('訓(xùn)練損失')
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('訓(xùn)練損失')
plt.plot(np.arange(len(losses)), losses, '-o', color='red')
plt.show()

plt.title()函數(shù)參數(shù)說明

fontsize設(shè)置字體大小,默認(rèn)12,可選參數(shù) [‘xx-small’, ‘x-small’, ‘small’, ‘medium’, ‘large’,‘x-large’, ‘xx-large’]

fontweight設(shè)置字體粗細(xì),可選參數(shù) [‘light’, ‘normal’, ‘medium’, ‘semibold’, ‘bold’, ‘heavy’, ‘black’]

fontstyle設(shè)置字體類型,可選參數(shù)[ ‘normal’ | ‘italic’ | ‘oblique’ ],italic斜體,oblique傾斜

verticalalignment設(shè)置水平對齊方式 ,可選參數(shù) : ‘center’ , ‘top’ , ‘bottom’ , ‘baseline’

horizontalalignment設(shè)置垂直對齊方式,可選參數(shù):left,right,center

rotation(旋轉(zhuǎn)角度)可選參數(shù)為:vertical,horizontal 也可以為數(shù)字

alpha透明度,參數(shù)值0至1之間

backgroundcolor標(biāo)題背景顏色

bbox給標(biāo)題增加外框 ,常用參數(shù)如下:

boxstyle方框外形
facecolor(簡寫fc)背景顏色
edgecolor(簡寫ec)邊框線條顏色
edgewidth邊框線條大小

到此這篇關(guān)于plt.title()中文無法顯示的問題解決的文章就介紹到這了,更多相關(guān)plt.title()中文無法顯示內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論