-1

Heres what I am attempting in matplotlib.pyplot using jupyter qtconsole as my interpreter:

In [1]: import matplotlib.pyplot as plt
In [2]: plt.plot([1,2,3])
Out[2]: [<matplotlib.lines.Line2D at 0x7ab5710>]
In [3]: plt.show()
plt.plot([4,5,6])
Out[4]: [<matplotlib.lines.Line2D at 0x7d8d5c0>]
In[5]: plt.show()
In[6]: plt.figure(1).show()
c:\python35\lib\site-packages\matplotlib\figure.py:403: UserWarning: matplotlib is currently using a non-GUI backend, so cannot show the figure
  "matplotlib is currently using a non-GUI backend, "

Both In[3] and In[5] successfully output an inline plot of the data. In[6] is my attempt at replotting the second figure. Unfortunately I am getting an error message about non-GUI back-end.

Ideally what I would like to do is first plot the data (eg using a script) and then modify the plot using the interpreter, replot it, see if I like the changes, modify some more, replot, etc. is this even possible using my setup above?

EDIT

There are two main differences with the supposed duplicate:

  • OP in the other question is using pylab which is deprecated
  • There is no explanation in the other question regarding my last point. Ok so there is no figure to show... That explains why no figure is output. That doesn't answer the question though. How to get a simple functional interface where the user can modify an existing plot and replot it at will?
user32882
  • 5,094
  • 5
  • 43
  • 82
  • 2
    Possible duplicate of [Showing the plot window more than once](https://stackoverflow.com/questions/15724747/showing-the-plot-window-more-than-once) – jotasi Oct 09 '17 at 08:02

1 Answers1

1

The behaviour in python console or script is surely a bit different than in jupyter qt console. For python scripts this answer is completely correct: There is no figure to show anymore after calling plt.show().
In jupyter qt console, a different backend is used, which will by default automatically plot the figures inline. This opens the possibility to use the object-oriented API and work with figure and axes handles.

Here, just stating the figure handle in a cell will make the figure be shown.

In [1]: import matplotlib.pyplot as plt

In [2]: fig, ax = plt.subplots()

In [3]: ax.plot([1,2,3])
Out[3]: [<matplotlib.lines.Line2D at 0xb34a908>]

In [4]: plt.show() # this shows the figure. 
# However, from now on, it cannot be shown again using `plt.show()`

# change something in the plot:
In [5]: ax.plot([2,3,1])
Out[5]: [<matplotlib.lines.Line2D at 0xb4862b0>]

In [6]: plt.show()  # this does not work, no figure shown

# However, just stating the figure instance will show the figure:
In [7]: fig
Out[7]: # image of the figure

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712