Separate saved image contents from live plot state

A technician runs the following script once in an initially empty output directory. Every save succeeds, and saving to an existing filename replaces that file. Each ax.plot call here adds one data-line object. Count these objects even if their drawings overlap; do not count coordinate-axis lines.


Python
import matplotlib.pyplot as plt

time_s = [0, 1, 2, 3]
runs_v = [
    [1, 2, 3, 4],
    [2, 3, 4, 5],
    [3, 4, 5, 6],
]

fig, ax = plt.subplots()

for readings_v in runs_v:
    ax.plot(time_s, readings_v)
    fig.savefig("trials.png")

ax.clear()
ax.plot(time_s, [4, 4, 4, 4])
fig.savefig("restart.png")
ax.plot(time_s, [6, 6, 6, 6])


Times are in seconds and readings are in volts. After the entire script finishes, report four exact integer counts: the number of PNG files in the directory, the number of data-line objects represented in trials.png, the number represented in restart.png, and the number remaining on the live ax object.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Matplotlib Questions: