是否可以使用 pyqtgraph 函数在 Jupyter Notebook 上内联绘图?
Is it possible to use pyqtgraph functions to plot inline on Jupyter Notebook?
我正在尝试使用 Pyqtgraph 在 Jupyter notebook 上绘制一些图像数组,但我遇到了一些问题。基本上,我使用以下代码:
import pyqtgraph as pg
%gui qt
pg.image(recon_array_a[0])
这给了我我需要的东西,但在新 window 中打开它。有没有办法打开内联?例如,可以在 Jupyter notebook 上使用 matplotlib 吗?
我不知道有什么方法可以在 jupyter notebook 中内联访问 pyqtgraph 等交互式 qt 应用程序。
如果您只对没有任何交互性的“原始图像”感兴趣,这里有一个解决方法:
- 用pyqtgraph生成图像
- 将此图像导出到临时文件
- 显示临时文件
这是一个快速演示(不再需要 %gui qt)
import pyqtgraph as pg
import pyqtgraph.exporters
import numpy as np
from IPython.display import display, Image
def show_image(data):
img = pg.image(data)
file_name = "temp.png"
exporter = pg.exporters.ImageExporter(img.imageItem).export(file_name)
img.close()
display(Image(filename=file_name))
data = np.array([[1,0],[2,3]])
show_image(data)
此线程中的贡献者取得了一些成功
https://groups.google.com/g/pyqtgraph/c/KImnC-hOTMA
QT 控制台也可能有助于让 Jupyter 和 Python
之间的通信正常进行
https://qtconsole.readthedocs.io/en/stable/
或者
https://bokeh.org/ and https://plotly.com/ 可能是您可以考虑的选项。
我正在尝试使用 Pyqtgraph 在 Jupyter notebook 上绘制一些图像数组,但我遇到了一些问题。基本上,我使用以下代码:
import pyqtgraph as pg
%gui qt
pg.image(recon_array_a[0])
这给了我我需要的东西,但在新 window 中打开它。有没有办法打开内联?例如,可以在 Jupyter notebook 上使用 matplotlib 吗?
我不知道有什么方法可以在 jupyter notebook 中内联访问 pyqtgraph 等交互式 qt 应用程序。
如果您只对没有任何交互性的“原始图像”感兴趣,这里有一个解决方法:
- 用pyqtgraph生成图像
- 将此图像导出到临时文件
- 显示临时文件
这是一个快速演示(不再需要 %gui qt)
import pyqtgraph as pg
import pyqtgraph.exporters
import numpy as np
from IPython.display import display, Image
def show_image(data):
img = pg.image(data)
file_name = "temp.png"
exporter = pg.exporters.ImageExporter(img.imageItem).export(file_name)
img.close()
display(Image(filename=file_name))
data = np.array([[1,0],[2,3]])
show_image(data)
此线程中的贡献者取得了一些成功
https://groups.google.com/g/pyqtgraph/c/KImnC-hOTMA
QT 控制台也可能有助于让 Jupyter 和 Python
之间的通信正常进行https://qtconsole.readthedocs.io/en/stable/
或者
https://bokeh.org/ and https://plotly.com/ 可能是您可以考虑的选项。