Python Matplotlib画图设置大标题和的大小、位置和粗细详解

设置标题大小
设置标题字体
设置标题位置
设置标题字体粗细
设置标题斜体

设置大标题大小
设置大标题字体
设置大标题位置
设置大标题字体粗细
设置大标题斜体

其实是大标题
设置副标题大小
设置副标题字体
设置副标题位置
设置副标题字体粗细
设置副标题斜体

from matplotlib import rcParams
import matplotlib.pyplot as plt

fig,axes = plt.subplots(1,1,figsize=(4,4),dpi=100,facecolor="w")
fig.subplots_adjust(left=0.2,bottom=0.2)

label_fontdict = {
    #'fontsize': rcParams['axes.titlesize'], # 设置成和轴刻度标签一样的大小
    'fontsize': 10,
    #'fontweight': rcParams['axes.titleweight'], # 设置成和轴刻度标签一样的粗细
    'fontweight': 'bold',
    #'color': rcParams['axes.titlecolor'], # 设置成和轴刻度标签一样的颜色
    'color': 'red',
    'verticalalignment': 'baseline',
    'horizontalalignment': 'left' # {'center', 'left', 'right'}
}
axes.set_title('title', fontdict=label_fontdict, loc='left', pad=0)

# x,y 控制suptitle标题的位置
# horizontalalignment 缩写ha 文本相对于(x, y)的水平对齐方式。{'center', 'left', 'right'}, default: center
# verticalalignment 缩写va 文本相对于(x, y)的垂直对齐方式。{'top', 'center', 'bottom', 'baseline'}, default: top
# fontweight default: 'normal'
fig.suptitle('suptitle', fontsize=24, x=0.6,y=0.9, horizontalalignment='left', va='bottom')
# 通过调整xy位置,和文字方向rotation,也可以将suptitle设置到y轴附近 

物联沃分享整理
物联沃-IOTWORD物联网 » Python Matplotlib画图设置大标题和的大小、位置和粗细详解

发表评论