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()
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.
Guilherme Diniz Queiroz De Car is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.