我有几个时间数据图如下:
比如这个时间系列从 2003.01 开始,到 2007.01 结束。我不知道为什么 matplotlib 决定将 xticks 放在一些不太方便阅读时间序列的随机位置。我希望在时间序列开始时有一个 xtick,然后在每年年初有另一个 xtick。
我不能使用“xlim”技巧,因为我有大约 1000 个不同的图。
这是我目前使用的代码
matplotlib.rcParams['text.latex.preamble']=[r"\usepackage{amsmath}"]
plt.style.use('fivethirtyeight')
def to_inch(cm):
return cm/2.54
rc('figure', **{
"facecolor": "white",
"figsize": (to_inch(11.7), to_inch(8.27),)
})
rc('text', usetex=False)
font = {
'family': 'serif',
'serif': ['Computer Modern'],
'size': 8
}
rc('font', **font)
labelsize = 6
linewidth = 0.5
axes = {
'labelsize': labelsize,
"edgecolor": '#cbcbcb',
"linewidth": linewidth,
"facecolor": "white"
}
rc("grid", **{"linewidth": linewidth})
rc('axes', **axes)
rc('legend', **{'fontsize': 5})
rc('xtick', **{"labelsize": labelsize})
rc('ytick', **{"labelsize": labelsize})
nc = Dataset("o_gg.nc", 'r+')
#Get time
time = num2date(nc.variables['time'[:],getattr(nc.variables['time'],'units'))
time_ctr_ch = np.array([ xx-dt.timedelta(hours=12,minutes=15) for xx in time])
ctr_chtessel_soil = nc.variables['SoilMoist'][:,:,0,0]
plt.plot(time_ctr_ch, ctr_chtessel_soil, c='lightsteelblue', linewidth=0.5
相关分类