0

I have read a Dataset in NC file using netCDF4 in python and then tried to plot the dataset using matplotlib.pyplot. But issue is the plot shows the image but with 90 Degrees clockwise rotation. Following code I have used:

from netCDF4 import Dateset
import matplotlib.pyplot as plt

f = Dataset(r'F:\data\data.nc', 'r')
data = f['et'][:]

plt.imshow(data)
plt.show()

Kindly let me know what can be the issue.

Also one doubt I am having, I have 2 NC files having same dataset and in that, dataset in one file is getting properly displayed by using np.rot90(data) which was suggested to me in the answer given below and in another file I need not to do "np.rot90(data)" but instead I need to do "data[::-1]" to display the data correctly.... And interesting thing is when I am importing these 2 files directly in the Arcmap both are getting properly displayed....can u suggest what can be the issue? Whether it's the issue with NC data?

  • I would strongly suggest to provide the input data. – AF7 May 24 at 18:16
0

I had the same issues when reading files using netCDF4. My approach was rotating the array 90 degrees in counter clockwise direction using np.rot90().

In your case:

from netCDF4 import Dateset
import matplotlib.pyplot as plt

f = Dataset(r'F:\data\data.nc', 'r')
data = f['et'][:]
data = np.rot90(data)  # rotate array

plt.imshow(data)
plt.show()
  • Thanks @Marcelo Villa "np.rot90(data)" worked for me....But one doubt I am having, I have 2 NC files having same dataset and in that, dataset in one file is getting properly displayed by using np.rot90(data) which you suggested and in another file I need not to do "np.rot90(data)" but instead I need to do "data[::-1]" to display the data correctly.... And interesting thing is when I am importing these 2 files directly in the Arcmap both are getting properly displayed....can u suggest what can be the issue.... – RRSC NGP May 25 at 4:28
  • Unfortunately, I do not know why this behaviour occurs. I saw you asked a new question regarding this issue and hope to see some answers. – Marcelo Villa May 26 at 0:56
  • whether it's the problem in NC files while it is being created? But I think it's not the actual cause because Arcmap is displaying both the NC files correctly.... If you get to know the reason please do let me know and if I got to know anything I will inform you.... – RRSC NGP May 26 at 2:08

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.