📜  Python中的 Matplotlib.pyplot.suptitle()函数

📅  最后修改于: 2022-05-13 01:54:37.676000             🧑  作者: Mango

Python中的 Matplotlib.pyplot.suptitle()函数

Matplotlib是Python中的一个库,它是 NumPy 库的数学扩展。 PyplotMatplotlib模块的基于状态的接口,它提供了一个类似 MATLAB 的接口。

matplotlib.pyplot.suptitle()函数

matplotlib 库的 pyplot 模块中的suptitle()函数用于为图形添加标题。

下面的示例说明了 matplotlib.pyplot 中的 matplotlib.pyplot.suptitle()函数:

示例 1:为图表添加标题,字体大小为 12。

Python3
# importing matplotlib.pyplot module
import matplotlib.pyplot as plt
  
# values of x and y axes
x = [6, 12, 18,
     24, 30, 36,
     42, 48, 54,
     60]
y = [1, 4, 3,
     2, 7, 6,
     9, 8, 10,
     5]
  
# plotting the graph 
plt.plot(x, y)
  
# labelling axes
plt.xlabel('x')
plt.ylabel('y')
  
# adding title to the graph
# with font size 12
plt.suptitle('This is the figure title', 
             fontsize = 12)
  
# show the plot
plt.show()


Python3
# importing matplotlib.pyplot module
import matplotlib.pyplot as plt
  
# values of x and y axes
x = [6, 12, 18,
     24, 30, 36,
     42, 48, 54,
     60]
  
y = [1, 4, 3,
     2, 7, 6,
     9, 8, 10,
     5]
  
# plotting the graph 
plt.plot(x, y)
  
# labelling axes
plt.xlabel('x')
plt.ylabel('y')
  
# Adding title to the graph 
# with left horizontal alignment
# and font size 12.
plt.suptitle('This is the figure title', 
             ha = 'left',
             fontsize = 12)


Python3
# importing matplotlib.pyplot module
import matplotlib.pyplot as plt
  
# values of x and y axes
x = [6, 12, 18,
     24, 30, 36,
     42, 48, 54,
     60]
  
y = [1, 4, 3,
     2, 7, 6,
     9, 8, 10,
     5]
  
# plotting the graph 
plt.plot(x, y)
  
# labelling axes
plt.xlabel('x')
plt.ylabel('y')
  
# Adding title to the graph 
# with extra bold font weight
# and large font size.
plt.suptitle('This is the figure title', 
             fontsize = 'xx-large',
             weight = 'extra bold')


输出 :

示例 2:为图表添加标题,左水平对齐和字体大小为 12。

Python3

# importing matplotlib.pyplot module
import matplotlib.pyplot as plt
  
# values of x and y axes
x = [6, 12, 18,
     24, 30, 36,
     42, 48, 54,
     60]
  
y = [1, 4, 3,
     2, 7, 6,
     9, 8, 10,
     5]
  
# plotting the graph 
plt.plot(x, y)
  
# labelling axes
plt.xlabel('x')
plt.ylabel('y')
  
# Adding title to the graph 
# with left horizontal alignment
# and font size 12.
plt.suptitle('This is the figure title', 
             ha = 'left',
             fontsize = 12)

输出:

示例 3:为图表添加标题,使用超粗字体粗细和大字体。

Python3

# importing matplotlib.pyplot module
import matplotlib.pyplot as plt
  
# values of x and y axes
x = [6, 12, 18,
     24, 30, 36,
     42, 48, 54,
     60]
  
y = [1, 4, 3,
     2, 7, 6,
     9, 8, 10,
     5]
  
# plotting the graph 
plt.plot(x, y)
  
# labelling axes
plt.xlabel('x')
plt.ylabel('y')
  
# Adding title to the graph 
# with extra bold font weight
# and large font size.
plt.suptitle('This is the figure title', 
             fontsize = 'xx-large',
             weight = 'extra bold')

输出: