我想要的一切都非常简单,我只希望定位器的滴答声在指定的时间戳记开始:
peudo code: locator.set_start_ticking_at( datetime_dummy )
到目前为止,我还没有找到任何东西的运气。
这是此问题的代码部分:
axes[0].set_xlim(datetime_dummy) # datetime_dummy = '2015-12-25 05:34:00'
import matplotlib.dates as matdates
seclocator = matdates.SecondLocator(interval=20)
minlocator = matdates.MinuteLocator(interval=1)
hourlocator = matdates.HourLocator(interval=12)
seclocator.MAXTICKS = 40000
minlocator.MAXTICKS = 40000
hourlocator.MAXTICKS = 40000
majorFmt = matdates.DateFormatter('%Y-%m-%d, %H:%M:%S')
minorFmt = matdates.DateFormatter('%H:%M:%S')
axes[0].xaxis.set_major_locator(minlocator)
axes[0].xaxis.set_major_formatter(majorFmt)
plt.setp(axes[0].xaxis.get_majorticklabels(), rotation=90 )
axes[0].xaxis.set_minor_locator(seclocator)
axes[0].xaxis.set_minor_formatter(minorFmt)
plt.setp(axes[0].xaxis.get_minorticklabels(), rotation=90 )
# other codes
# save fig as a picture
Run Code Online (Sandbox Code Playgroud)
上面代码的x轴刻度会告诉我:
如何告诉次要定位器与主要定位器对齐?
如何告诉定位器从哪个时间戳开始计时?
我曾尝试:
set_xlim
不会做的伎俩
seclocator.tick_values(datetime_dummy, datetime_dummy1)
不会做任何事情
而不是使用interval
关键字参数,而是使用bysecond
和byminute
来指定要标记的秒和分钟。的bysecond
和byminute
参数被用来构造dateutil RRULE。的rrule
产生匹配该特定的指定模式(或者,也可以说,“规则”)日期时间。
例如,bysecond=[20, 40]
将日期时间限制为second
s等于20或40 的日期时间。因此,在下面,次刻度线仅出现在秒数等于20或40的日期时间。
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as matdates
N = 100
fig, ax = plt.subplots()
x = np.arange(N).astype('<i8').view('M8[s]').tolist()
y = (np.random.random(N)-0.5).cumsum()
ax.plot(x, y)
seclocator = matdates.SecondLocator(bysecond=[20, 40])
minlocator = matdates.MinuteLocator(byminute=range(60)) # range(60) is the default
seclocator.MAXTICKS = 40000
minlocator.MAXTICKS = 40000
majorFmt = matdates.DateFormatter('%Y-%m-%d, %H:%M:%S')
minorFmt = matdates.DateFormatter('%H:%M:%S')
ax.xaxis.set_major_locator(minlocator)
ax.xaxis.set_major_formatter(majorFmt)
plt.setp(ax.xaxis.get_majorticklabels(), rotation=90)
ax.xaxis.set_minor_locator(seclocator)
ax.xaxis.set_minor_formatter(minorFmt)
plt.setp(ax.xaxis.get_minorticklabels(), rotation=90)
plt.subplots_adjust(bottom=0.5)
plt.show()
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3642 次 |
最近记录: |