I have the following code that generates a plot:
import numpy as np
import matplotlib.pyplot as plt
import xarray as xr
data = xr.open_dataset('mypath/data.nc')
lat=np.array(data['latitude'][:])
lon=np.array(data['longitude'][:])
u = np.array(data['u'][:])
u = u.reshape(len(lat),len(lon))
fig, ax = plt.subplots(1,1,figsize=(8, 6))
X,Y=np.meshgrid(lon,lat)
ax.contourf(X,Y,u)
Python Plot
How can I add a colorbar?
I tried plt.colorbar().
New contributor
s28 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.