Search code examples
pythonmatplotlibnetcdf4

Matplotlib only showing half of the data when it comes to plotting a map


I'm new in programming with python and was trying to get a map of the "sst", what happened is that the map always comes in half when it comes to showing the data itself.

from matplotlib import pyplot as plt
from netCDF4 import Dataset
import numpy as np
from mpl_toolkits.basemap import Basemap

#the path the program will read;
data = Dataset('sst.day.mean.1981.nc')
#extracting variables.
lats= data.variables['lat'][:]
lons = data.variables['lon'][:]
time = data.variables['time'][:]
sst = data.variables['sst'][:]


#here i start defining the map
mp = Basemap(projection = 'cyl')
lon, lat = np.meshgrid(lons, lats)
#the abscissa and ordinate will be defined based on longitude and latitude, respectively.
x, y = mp(lon, lat)

c_scheme = mp.pcolor(x, y, np.squeeze(sst[0,:,:]), cmap = 'jet')
mp.drawcoastlines()
mp.drawstates()
mp.drawcountries()
plt.title('Sea surface temperature')
plt.show()

The image obtained with the code above.

I saw someone with a similar problem and tried adapting the solution to my code, but not understanding enough of matplotlib just let me to the same result, since I couldn't really understand how matplotlib really arranges from 0 to 360 or -180 to 180.


Solution

  • you should set the latlon value to True

    c_scheme = mp.pcolor(x, y, sst[0,:,:], cmap = 'jet', latlon = True)
    

    output:

    enter image description here