- 設(shè)置標(biāo)題大小、字體、位置、字體粗細(xì)、斜體(二級(jí))
- 設(shè)置大標(biāo)題
suptitle
標(biāo)題大小、字體、位置、字體粗細(xì)、斜體(一級(jí))
import matplotlib.pyplot as plt
fig,axes = plt.subplots(1,1,figsize=(6,6),dpi=100,facecolor="w")
#調(diào)整圖的四周間距
fig.subplots_adjust(left=0.2,bottom=0.3)
# 單獨(dú)設(shè)置軸刻度標(biāo)簽的字體
# axis {'x', 'y', 'both'}, default: 'both'
# which {'major', 'minor', 'both'}, default: 'major'
# pad
axes.tick_params(axis='x',which='major', labelsize=18,color='#ff0000',width=4,length=7,
labelcolor='#ff00ff',pad=10)
xlabel_font = {
#'fontsize': rcParams['axes.titlesize'], # 設(shè)置成和軸刻度標(biāo)簽一樣的大小
'fontsize': 20,
#'fontweight': rcParams['axes.titleweight'], # 設(shè)置成和軸刻度標(biāo)簽一樣的粗細(xì)
'fontweight': 'light',
#'color': rcParams['axes.titlecolor'], # 設(shè)置成和軸刻度標(biāo)簽一樣的顏色
'color': 'blue',
}
# fontdict 設(shè)置字體的相關(guān)屬性
# labelpad 設(shè)置軸名稱到軸的間距
# loc 設(shè)置x軸是靠那邊對(duì)其
axes.set_xlabel('x軸名稱', fontdict=xlabel_font,labelpad=20,loc='right')
ylabel_font = {
#'fontsize': rcParams['axes.titlesize'], # 設(shè)置成和軸刻度標(biāo)簽一樣的大小
'fontsize': 28,
#'fontweight': rcParams['axes.titleweight'], # 設(shè)置成和軸刻度標(biāo)簽一樣的粗細(xì)
'fontweight': 'bold',
#'color': rcParams['axes.titlecolor'], # 設(shè)置成和軸刻度標(biāo)簽一樣的顏色
'color': 'red',
}
axes.set_ylabel('y軸名稱',fontdict=ylabel_font,labelpad=4)
title_fontdict = {
#'fontsize': rcParams['axes.titlesize'], # 設(shè)置成和軸刻度標(biāo)簽一樣的大小
'fontsize': 12,
#'fontweight': rcParams['axes.titleweight'], # 設(shè)置成和軸刻度標(biāo)簽一樣的粗細(xì)
'fontweight': 'bold',
#'color': rcParams['axes.titlecolor'], # 設(shè)置成和軸刻度標(biāo)簽一樣的顏色
'color': 'red',
'verticalalignment': 'baseline',
'horizontalalignment': 'left' # {'center', 'left', 'right'}
}
axes.set_title('標(biāo)題', fontdict=title_fontdict, loc='left', pad=6)
fig.suptitle('大標(biāo)題', fontsize=24, x=0.6,y=0.95, horizontalalignment='left', va='bottom')
axes.set_xlim(0,10)
# 也可以單獨(dú)修改,
font={
'style': "italic",
'weight': "normal",
'fontsize':20,
'color': '#00ff00',
}
# x,y 控制文本的位置
axes.text(7,0.5,'文本', fontdict=font)
# 文字旋轉(zhuǎn)角度方向 rotation
axes.text(2, 0.3, s='文字旋轉(zhuǎn)角度180', fontsize=20, rotation=180)
文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-635573.html
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-635573.html
到了這里,關(guān)于Python matplotlib 畫圖 設(shè)置標(biāo)題 大標(biāo)題 副標(biāo)題 大小、位置、粗細(xì)全集的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!