python - Matplotlib figure doesn't display correctly when re-opening -
I have an application that I'm running from a python shell. I have a main shape
fig, (plt1, plt2, plt3) = pl.subplots (3, 1) I have the following functions :
def do_select_features (auto, line): global mode, fig mode = 'features' fig.canvas.mpl_connect ('key_press_event', on_key) plot_wnd () pl.ion () pl. Show () def plot_wnd (): plt1.cla () plt2.cla () plt3.cla () plt1.grid (true) plt2.grid (true) plt3.grid (true) plt1.hold (true) plt1.plot (Rdata) plt1.plot ([rng_current [0], rng_current [0]], [minute (rdata), max (rdata)] 'r', lw = 1) plt1.plot ([rng_current [1], rng_current [1]], [minute (rdata), max (rdata)], 'r', lw = 1) zdata = compression.fill_in (compression.zigzag (normal, curved)) plt2.plot (z Data [rng_current [0]: rng_current [1]], color = 'r') plt2.plot (normal (rdata) [rng_current [0]: rng_current [1]], color = 'b') plt3.plot (diff (Zdata, normal (Rdata)) [rng_current [0]: rng_current [1]], color = 'r' pl.draw () def on_key (event): global rng_current if event.key == 'right' and (rng_current [1] + stp) & lt; Lane (rdata): rng_current [0] + = STP rng_current [1] + = STP plot_wnd () if event.key == 'Access': f = h5py.File (db, "a") pdo.insert_group (f, Mode, compression.zigzag (iframe [rng_current [0]: rng_current [1]]), zigzag f.close print "Added to subseries", mode, "database" if event.key == 'left' and (Rng_current [0] - stp) & gt; 0: rng_current [0] - = stp rng_current [1] - = + stp plot_wnd () if event.key == 'escape': pl.close () So when I am In the command line, I call select_features and pulls this figure and everything works great I manually exit the window with my mouse or hit ESC (which turns on pl.close). Then again I want to be able to call select_features, but it always brings a similar window that is all gray. How do I fix this?
Try creating your fig inside the function. Window, if you destroy this data, then the function can not reach that figure so far to call the function. Every time you create a new window, you need to create a new shape.
Comments
Post a Comment