Reputation: 1843
I'm having trouble with a plot because an input prevents the plot to be displayed. I have a large code which manipulate some data and plot it, then ask some questions about the plot (with which then makes another plot). Im running the code from another notebook so, although the plot and the input are in diferent cells, the plot it isn't displayed until i make the input,here is a short example of the problem:
%matplotlib nbagg
import matplotlib.pyplot as plt
plt.plot([1,2,3,4,5,6,7,8])
input('Gimme a number: ')
supose the code above is in Notebook1, if i open a new Notebook2 and from there run Notebook1 (%run Notebook1.ipynb
), the first thing that pops is the input
and the only thing that appears from the plot are the controls; the plot only appears after i make the input which is not good since i need to see the plot to make the correct input. I've tried with plt.show()
with no results and if i use plt.draw()
the plot is displayed but in non interactive mode so i can't make zoom or move through the data, this mode only activates after i make the input.
Anyone have any idea how to solve this?
Upvotes: 6
Views: 2916
Reputation: 12610
Calling plt.gcf().canvas.draw()
after plotting and before input
worked for me.
Upvotes: 0
Reputation: 697
Have you tried turning on the interactive mode using plt.ion()
before sending the plot command?
Upvotes: 1