Python Matplotlib. yplot. title Plot settings title

PLT.title

import random
import matplotlib.pyplot as plt
#generate random dataset 
x = range(10)
y = [random.randint(1,100) for i in range(10)]
#draw a line chart 
plt.plot(x,y)
###############################set title ###############################
plt.title(
label = "This is title",
fontdict={
  "fontsize":20,  #font size 
  "color":"white",#font color 
  "family":"Times New Roman",     #font type, can refer to :https://blog.csdn.net/weixin_45492560/article/details/123980725
  "fontweight":"black",           #font line thickness, optional parameters :{"light": ,"normal":,"medium":,"semibold":,"bold":,"heavy":,"black"}
  "fontstyle":"italic",           #font type, optional parameters :normal、italic italic oblique tilt 
  "verticalalignment":"center",   #set horizontal alignment, optional parameters :center、top、bottom、baseline
  "horizontalalignment":"center", #set vertical alignment method, optional parameters :left、right、center
  "rotation":0, #rotation angle, optional parameters are :vertical,horizontal it can also be a number 
  "alpha":1,    #transparency, parameter values between 0 and 1 
  "backgroundcolor":"black",#title background color 
  #set outer border 
  "bbox":{
      "boxstyle":"round",  #border type, reference :https://vimsky.com/examples/usage/python-matplotlib.patches.BoxStyle-mp.html
      "facecolor":"black", #the background color seems to match the above backgroundcolor there is a conflict 
      "edgecolor":"red",   #border line color 
  },
},
)
#######################################################################
plt.show()

Ax.set_Title

  • This article only shows the differences from the previous text
#####################related to plt.title differences #####################
fig,ax=plt.subplots(1,1)
ax.plot(x,y)
fontdict={......} #this dictionary is consistent with the previous text fontdict unanimous 
ax.set_title(
"This is title",
fontdict = fontdict
)
plt.show()