2017-10-09 40 views
-1

继承人什么我试图在matplotlib.pyplot使用jupyter qtconsole我的翻译:不能重新剧情人物

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, " 

两个In[3]In[5]成功地将数据输出的直列情节。 In[6]是我重新绘制第二张图的尝试。不幸的是,我收到了关于非GUI后端的错误消息。理想情况下,我想要做的是首先绘制数据(例如使用脚本),然后使用解释器修改绘图,重新绘制它,看看我是否喜欢这些变化,修改更多,重绘等等。这甚至可能使用我的设置上面?

编辑

有与应该重复的两个主要区别:它被废弃

  • 有一个在其他问题就没有解释

    • OP中的其他问题是使用pylab我的最后一点。好,所以没有数字显示......这就解释了为什么没有数字输出。这并没有回答这个问题。如何获得一个简单的功能界面,用户可以修改现有的绘图并随意重新绘制它?
  • +2

    的[显示图形窗口不止一次]可能的复制(https://stackoverflow.com/questions/15724747/showing-the-plot-window-more一次-than) – jotasi

    回答

    0

    在python控制台或脚本中的行为肯定有点不同于在jupyter qt控制台。对于Python脚本this answer是完全正确的:调用plt.show()之后没有数字显示。
    在jupyter qt控制台中,使用了不同的后端,默认情况下会自动将内联数字内联。这样可以使用面向对象的API并使用图形和坐标轴手柄。

    在这里,只是在单元格中指定图柄会使图形显示出来。

    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