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

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



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

Updated on: 2021-06-05T08:14:50+05:30

10K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements