Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法在matplotlib中重新绘制地物_Python_Matplotlib - Fatal编程技术网

Python 无法在matplotlib中重新绘制地物

Python 无法在matplotlib中重新绘制地物,python,matplotlib,Python,Matplotlib,以下是我试图在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

以下是我试图在
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, "
[1]中的
:将matplotlib.pyplot作为plt导入
[2]中:plt.plot([1,2,3])
输出[2]:[]
在[3]:plt.show()中
plt.绘图([4,5,6])
Out[4]:[]
[5]:plt.show()
[6]中:plt.图(1).show()
c:\python35\lib\site packages\matplotlib\figure.py:403:UserWarning:matplotlib当前正在使用非GUI后端,因此无法显示该图
matplotlib当前正在使用非GUI后端
[3]中的
和[5]
中的
都成功地输出了数据的内联图<[6]
中的code>是我试图重新填充第二个图。不幸的是,我收到了一条关于非GUI后端的错误消息

理想情况下,我想做的是首先绘制数据(如使用脚本),然后使用解释器修改绘图,重新打印,看看我是否喜欢这些更改,再修改一些,重新打印,等等。使用上面的设置,这可能吗

编辑

与假定的副本有两个主要区别:

  • 另一个问题中的OP是使用
    pylab
    ,这是不推荐使用的
  • 关于我的最后一点,另一个问题没有解释。好的,所以没有数字显示。。。这就解释了为什么没有数字输出。但这并不能回答问题。如何获得一个简单的功能界面,用户可以修改现有的绘图并随意重新打印

python控制台或脚本中的行为肯定与jupyter qt控制台中的行为有所不同。因为python脚本是完全正确的:调用
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
[1]中的
:将matplotlib.pyplot作为plt导入
在[2]中:图,ax=plt.subplot()
[3]中:ax.绘图([1,2,3])
输出[3]:[]
[4]:plt.show()#这显示了该图。
#但是,从现在起,不能使用'plt.show()再次显示它`

#更改绘图中的某些内容:
[5]中:ax.绘图([2,3,1])
输出[5]:[]
[6]中:plt.show()#这不起作用,没有显示任何图形
#但是,仅说明figure实例即可显示该图:
在[7]中:图
Out[7]:#图的图像

可能存在的副本