Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.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
如何让基本的交互式pyqtgraph绘图在IPython REPL或Jupyter控制台中工作?_Ipython_Pyqtgraph - Fatal编程技术网

如何让基本的交互式pyqtgraph绘图在IPython REPL或Jupyter控制台中工作?

如何让基本的交互式pyqtgraph绘图在IPython REPL或Jupyter控制台中工作?,ipython,pyqtgraph,Ipython,Pyqtgraph,打字 在标准Python REPL中打开一个包含数据图的窗口。在IPython REPL或Jupyter控制台中键入完全相同的代码,不会打开这样的窗口 [可通过键入pg.QtGui.QApplication.exec齌()使窗口显示,但随后REPL被阻止 或者,当尝试退出REPL并且需要确认时,会出现该窗口 这两项都非常不令人满意。] 如何使基本交互式pyqtgraph绘图与IPython REPL一起工作 [在IPython 5.1.0和Jupyter 5.0.0中观察到描述的行为,使用Pyt

打字

在标准Python REPL中打开一个包含数据图的窗口。在IPython REPL或Jupyter控制台中键入完全相同的代码,不会打开这样的窗口

[可通过键入
pg.QtGui.QApplication.exec齌()
使窗口显示,但随后REPL被阻止

或者,当尝试退出REPL并且需要确认时,会出现该窗口

这两项都非常不令人满意。]

如何使基本交互式pyqtgraph绘图与IPython REPL一起工作


[在IPython 5.1.0和Jupyter 5.0.0中观察到描述的行为,使用Python 3.5和3.6以及PyQt4和PyQt5(无PySide)]

正如@titusjan所建议的,解决方案是键入

import pyqtgraph as pg
pg.plot([1,2,3,2,3])

在发出任何pyqtgraph(或一般的PyQt)命令之前,请先查看IPython中的
%gui?
)还有哪些其他选项可用。

我在Jupyter笔记本中遇到matplotlib问题。速度不够快,我发现导航有缺陷。我让pyqtgraph使用我在这里找到的提示来工作。天啊!这是一个很棒的工具。你的导航和速度都很棒

我想我会在这里分享我的解决方案

%gui qt
你会得到一个这样的弹出窗口

首先尝试在终端中键入
%gui qt
。是的,这解决了问题。jupyterlab呢?
%gui qt5
from PyQt5.Qt import QApplication

# start qt event loop
_instance = QApplication.instance()
if not _instance:
    _instance = QApplication([])
app = _instance

import pyqtgraph as pg

# create and and set layout
view = pg.GraphicsView()   
view.setWindowTitle('Your title')
layout = pg.GraphicsLayout()
view.setCentralItem(layout)
view.show()

# Set white graph
pg.setConfigOptions(antialias=True)
pg.setConfigOption('background', 'w')
pg.setConfigOption('foreground', 'k')

# add subplots
p0 = layout.addPlot(0,0)
p0.addLegend()
p0.plot([1,2,3,4,5], pen='b', name='p0')

p1 = layout.addPlot(1,0)
p1.addLegend()
p1.plot([2,2,2,2,], pen='r', name='p1')

p2 = layout.addPlot(1,0)
p2.addLegend(offset=(50, 0))
p2.plot([-1,0,1,1,], pen='g', name='p1.1')
p2.hideAxis('left')
p2.showAxis('right')