I'm working with a GUI that centers around a matplotlib plot in the window. What I want to achieve is for the user to be able to interact with the plot easily and intuitively.

My current objective is to plot curves, and have the curves be highlighted (thicker line width) as the mouse hovers over.

I've already got the events setup and I have good algorithms for detecting when it's close enough. The part I'd like to optimize is the drawing portion. I'll describe the logic I'd like to achieve.

1. Draw all of the paths with normal line width
2. Detect mouse over line
3. Push current axis (save it)
4. Draw highlighted line (thicker line width)
5. Detect mouse leaving line
6. Pop current axis (get rid of highlighted line)

The idea of pushing and popping is that you have a stack of rasterized images. When you push the current display, it saves it on the stack, and you're given a new raster to draw on that starts out identical to what you just pushed. What is displayed is what is on the top of the stack. When you pop it, what is on the top is lost, and you are back to what you had previously pushed.

What I first tried to do was make a deep copy of the axis and save it as a variable on the axis. This did not work. I wanted to see if there were any better alternatives for what I'm trying to accomplish.