I was able to get an answer on stackoverflow. If anyone is interested the answer can be seen at the listed stackoverflow url.
I would like to be able to use a button press within an embedded tkinter
matplotlib graph to switch from one graph to another. The code I have
written does not replace the first graph with the second graph but just adds
the second graph underneath the first graph. How can I get the button press
to replace the first graph with the second graph rather than just add the
second graph below the first graph?
The graphs that I have coded, graph_one and graph_two, are two simple graphs that I pulled from the matplotlib documentation. In my actual use I have two much more complicated graphs that are very dissimilar, one is a single plot and the other has an additional subplot. Because the graphs I wish to switch back and forth between are so dissimilar it is important to me that the solution be able to handle the graph inputs as separate definitions. It should also be noted that my graphs are embedded in a tkinter widget and it is important that the solution also account for this embedding. Here is the code I have:
import matplotlib.pyplot as plt
import numpy as np
from tkinter import *
from matplotlib.backends.backend_tkagg import (
# Implement the default Matplotlib key bindings.
from matplotlib.backend_bases import key_press_handler
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2 * np.pi * t)