Search code examples
pythonvisual-studio-codeplotpyqtgraph

pyqtgraph: how to make simple plot in vs code?


I am new to pyqtgraph but I cannot get it to work. I run the following code in VS code as a jupyter cell:

# %%
import pyqtgraph as pg
import numpy as np
x = np.linspace(0,10)
y = np.linspace(0,10)
X, Y = np.meshgrid(x, y)
img = np.sin(X)*np.sin(Y)
pg.image(img)

Then I get a frozen cell that is not responding. How do I get a simple plot in pyqtgraph?

enter image description here


Solution

  • Adding pg.exec() at the end should do it. For more information for beginners I recommend looking into the example programs (run pyqtgraph.examples.run()). They can be quite complex but there are not a whole lot of other good resources as far as I'm aware.