Reputation: 175
I am trying to use Pyqtgraph to plot some image arrays on Jupyter notebook, but I am having some problems. Basically, I'm using the following code:
import pyqtgraph as pg
%gui qt
pg.image(recon_array_a[0])
This is giving me what I need but is opening it in a new window. Is there a way to open inline? Like is possible to do using matplotlib on Jupyter notebook, for exemple?
Upvotes: 4
Views: 1355
Reputation: 1480
Pyqtgraph contributor here.
For future visitors, somewhat recent updates allow embedding some pyqtgraph widgets into notebooks via jupyter_rfb
. Check out the binder instance for examples.
Upvotes: 4
Reputation: 341
A contributor in this thread had some success
https://groups.google.com/g/pyqtgraph/c/KImnC-hOTMA
QT Console may also help get the communication working between Jupyter and Python
https://qtconsole.readthedocs.io/en/stable/
Alternatively
https://bokeh.org/ and https://plotly.com/ might be options for you to consider.
Upvotes: 1
Reputation: 3721
I am not aware of a way to make interactive qt applications such as pyqtgraph accessible inline in a jupyter notebook.
If you are only interested in the "raw image" without any interactivity, here's a workaround for you:
Here's a quick demo (%gui qt is not required anymore)
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)
Upvotes: 4