Target the correct figure when saving and closing

An engineer creates separate graphics for a sensor run and a calibration check. Assume both figures remain open after this code executes.


Python
import matplotlib.pyplot as plt

run_fig, run_ax = plt.subplots()
run_ax.plot([0, 1, 2], [2.1, 2.8, 3.4])

check_fig, check_ax = plt.subplots()
check_ax.plot([0, 1, 2], [2.0, 2.0, 2.0])


The horizontal values are times in seconds, and the vertical values are voltages in volts. Complete the instructions using variable names from the code.


To save only the sensor-run graphic, put before .savefig("sensor_run.png").


To close only the calibration-check figure, pass as the argument to plt.close(...).

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: