Using PyQtGraph, my surface will appear at the bottom left of the window.

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 problem may be related to the library's interaction with the Mac layout. Not really sure what it might be and how to solve it. Should I learn to use another program?

+3


source to share


1 answer


I had the same problem on my Macbook Pro. I think something from the version of PyQtGraph you have installed is not allowing your (and most Macs) devices to scale properly.

I didn't confuse too much, but to get around this I created a new Python environment in Anaconda (to make sure any other dependencies don't call this) and installed the version of PyQtGraph available through Conda. I don't know if other versions from other sources will work, but it seems to work for me.

If you have Anaconda installed on your computer, just follow these steps:



  • Create a new Python environment. conda create -n env_name python=py_ver anaconda

  • The source of your environment. source activate env_name

  • Install PyQtGraph. conda install -c anaconda pyqtgraph

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

0


source







All Articles