我使用ob间谍来绘制地震记录,但是当您想要定制一些绘图时,您必须使用matplotlib。但通过这种方式,我无法成功地使用日期时间来使用x轴,第一个标签显示所有日期,然后只显示秒(或%M:%S最终)。
在这里,使用ob间谍的情节:

看日期,时间,斧头。
在这里,我使用matplotlib绘制的图:

如何获得与以往相同时间的斧头?
最后是matplotlib图的代码:
trz = st[2].copy()
tr=trz.trim(starttime=t0, endtime=(t0+float(dur)), nearest_sample=True)
tr.filter("bandpass", freqmin=float(flow), freqmax=float(fhigh), corners=2, zerophase=True)
t = np.arange(0, tr.stats.npts / tr.stats.sampling_rate, tr.stats.delta)
label=(tr.stats.network + '.' + tr.stats.station + '.' + tr.stats.location + '.' + tr.stats.channel)
fig, ax = plt.subplots(1,1,figsize=(18,10), dpi=200)
ax.plot(t,tr.data, 'r', label=label)
ax.set_title('Évènement du '+str(date)+'T'+str(hr)+' station : '+str(sta) + '_' + tr.stats.channel)
ax.xaxis.grid(True, which='major', color='g', linestyle='dotted', linewidth=0.3)
ax.yaxis.grid(True, which='major', color='g', linestyle='dotted', linewidth=0.3)
ax.legend(loc='upper left', ncol=4)
ax.set_xlim(tr.stats.starttime,tr.stats.endtime)
formatter = mdates.DateFormatter("%H-%M-%S")
ax.xaxis.set_major_formatter(formatter)
locator = mdates.HourLocator()
ax.xaxis.set_major_locator(locator)发布于 2022-06-08 14:12:41
使用set_xlabel()可能是一种解决方案(谢谢DPM),但是跟踪轴似乎没有与数据同步。
最后,使用xlim解决日期格式(?),然后使用matplotlib数据格式化程序来定制时间间隔。
ax.set_xlim((pd.to_datetime(str(tr.stats.starttime))),(pd.to_datetime(str(tr.stats.endtime))))
ax.xaxis.set_major_formatter(mdates.DateFormatter('%H:%M:%S'))
ax.xaxis.set_major_locator(mdates.SecondLocator())其结果是:

但是,我不知道如何在使用all格式的日期(%Y-%m-%dT%H:%M:%S)上有第一个标签,但也许这并不重要.
https://stackoverflow.com/questions/72541989
复制相似问题