I am having a NetCDF data with one dimension that varies with time for 1000 years (1 year interval from 850 to 1849). I am plotting a time series and I want to show only years in the X-axis (850 to 1849). I have used the following script but it doesn't work.
import netCDF4 as netcdf
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import datetime
nc = netcdf.Dataset('tas_850-1849.nc')
time = nc.variables['time']
lat = nc.variables['lat'][:]
lon = nc.variables['lon'][:]
var = nc.variables['pdo'][:]
start = datetime.date(850,01,01)
dates = [start + datetime.timedelta(n) for n in range(len(var))]
plt.plot(dates, var[:,0,0], color='red', linewidth=2, label='Data1')
plt.show()
I get the following image which is not the way I want.
Time series line plot with time in X-axis.