In the code below, lib is an alias for the mathematical plotting library named matplotlib.

I only want to change the title of the plot for one of many plots or figures.

I do not want to change the titles of all plots and figures, only one plot or figure.


import numpy as np
import matplotlib.pyplot as lib

# Begin plot 1 of 2

# begin generating x-axis (horizontal axis) values for plot or figure one

xs = np.array(list(range(0, 10)))

# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

# finish generating x-axis (horizontal axis) values for plot or figure one

####################################################################

# begin generating x-axis (horizontal axis) values for plot or figure two

exs = np.arange(0, 20, .1)

# [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, ... 19.7, 19.8, 19.9, 20.0]

# finish generating x-axis (horizontal axis) values for plot or figure two

####################################################################

# begin generating the values for the y-axis (vertical axis) of plot or figure one

f = lambda x: x**2+100

ys   = np.array([f(x) for x in xs])

# ys = [0^2+100, 1^2+100, 2^2+100, 3^2+100, 4^2+100, 5^2+100, ..., 9^2 + 100]

# finish generating the values for the y-axis (vertical axis) of plot or figure one

####################################################################

# Begin generating the values for the y-axis of plot 2

g = lambda x: 10*x + 9

whys = np.array([g(x) for x in exs])

# Finish generating the values for the y-axis of plot 2

####################################################################

p1 = lib.plot(xs, ys)

p2 = lib.plot(exs, whys)

####################################################################

lib.title("Sports Watch Data")

lib.xlabel("Average Pulse Rate")

lib.ylabel("Number of Calories Burned")

lib.show()

The line of code lib.title("Sports Watch Data") seems to assign a plot title “Sport Watch Data” to the entire library of code, where the handle, or label, for the entire library is lib.

We want to set the title for only the plot having name, handle, or label p1.

How do we mutate the value of, or set a new value for, the title plot p1 without mutating the title of plot p2?