Setting the Matplotlib title in bold while using "Times New Roman"

MatplotlibPythonData Visualization

To set the Matplotlib title in bold while using "Times New Roman", we can use fontweight="bold".

Steps

  • Set the figure size and adjust the padding between and around the subplots.
  • Create a figure and a set of subplots.
  • Create x and y data points using numpy.
  • Plot x and y data points using scatter() method.
  • Set the title of the plot using fontname="Times New Roman" and fontweight="bold"
  • To display the figure, use show() method.

Example

import numpy as np
from matplotlib import pyplot as plt, font_manager as fm

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

fig, ax = plt.subplots()
x = np.random.rand(100)
y = np.random.rand(100)
ax.scatter(x, y, c=y, marker="v")

ax.set_title('Scatter Plot With Random Points', fontname="Times New Roman", size=28,fontweight="bold")

plt.show()

Output

raja
Published on 05-Jun-2021 08:13:55
Advertisements