Using PyQtGraph my Surface Plot displays in the bottom left quarter of the window.

Viewed 1535

Here is my code.

from pyqtgraph.Qt import QtGui
import numpy as np
import pyqtgraph.opengl as gl
from netCDF4 import Dataset
import sys

def main():

    app = QtGui.QApplication(sys.argv)
    w=gl.GLViewWidget()
    w.show()
    w.setCameraPosition(distance=150)

    #just my data
    data=Dataset('200707.nc')


    prec=data.variables['Prec'][5,:59,:59]

    p = gl.GLSurfacePlotItem(z=prec[:] ,shader='heightColor')
    p.shader()['colorMap'] = np.array([0.2, 2, 0.5, 0.2, 1, 1, 0.2, 0, 2])


    w.addItem(p)
    sys.exit(app.exec_())

if __name__ == '__main__':

    main()

I think the issue could be in the library's interaction with my Mac's pixel layout. Really not sure what it could be or how to resolve it. Should I looking into using a different program?

2 Answers

I had the same problem on my Macbook Pro. I think something from the version of PyQtGraph you have installed isn't allowing for proper scaling on your (and most Mac) devices.

I haven't really messed around too much, but to get around this I created a new Python environment in Anaconda (to make sure any other dependencies aren't causing this) and installed the version of PyQtGraph that's available through Conda. I don't know if other versions through other sources will work as well, but this one seems to work for me.

If you have Anaconda installed on your computer, simply do the following:

  • Create a new Python environment. conda create -n env_name python=py_ver anaconda
  • Source to your environment. source activate env_name
  • Install PyQtGraph. conda install -c anaconda pyqtgraph

Now when you run your program, it should scale properly.

Had a problem like this after installing vispy on osx. Turns out I just needed to install the latest version of pyqt5 and the problem went away.

pip install pyqt5

Related