I have some variable in my NetCDF4. I have 2 type of variable IR ( infrared) or VIS visible all time when when I choose var to plot in list_ var in index I need to choose cmap :

Dor IR the cmap is cmap=plt.cm.gist_yarg and for VIS cmap=plt.cm.gist_gray

This part of my code :

        nc = netCDF4.Dataset(file_names)

        var = nc.variables.keys()

        list_var = [nc.variables['VIS006'],nc.variables['VIS008'],nc.variables['IR_120'],nc.variables['IR_108'],nc.variables['IR_087'],
        data_list = ['VIS006','VIS008','IR_120','IR_108','IR_087','IR_134','IR_039','WV_073','WV_062','IR_097']

        list_var = [nc.variables[f] for f in data_list]
        print("Option chosen update")
        global index


How can I use condition if in my code like this :

 #if "IR" in var :
           # plt.imshow(data1,vmin=mini,vmax=maxi, cmap=plt.cm.gist_yarg)
        #elife  "VIS" in var :
            #plt.imshow(data1,vmin=mini,vmax=maxi, cmap=plt.cm.gist_gray)
           # plt.imshow(data1,vmin=mini,vmax=maxi)
  • 1
    Please format all code appropriately and reduce it to the bare necessities. – bugmenot123 May 28 at 8:28
  • the code is in wxpython that why is not clear – Sarah Tohami May 28 at 9:43
  • That does not matter, fix the indentation and formatting and it will be more readable. – bugmenot123 May 28 at 10:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.