只显示每十个标签是有点危险的
等间距的数据,因为你不知道中间会发生什么。
不过,要运行脚本,您当然需要确定位置
xx
是数组的有效索引。例如,位置
100
import numpy as np
import matplotlib.pyplot as plt
import pandas as p
import matplotlib.ticker as ticker
file1=np.load('data/numofdays.npz')
fig,ax=plt.subplots(ncols=1)
x=np.arange(len(file1['arr_0']))
y=np.array(file1['arr_0'])
ax.bar(x,y)
mydates=p.DatetimeIndex(file1['arr_1'])
def mme(xx,pos=None):
if int(xx) in x:
return mydates[int(xx)].strftime('%Y-%m-%d')
else:
return ""
ax.xaxis.set_major_locator(ticker.MultipleLocator(10))
ax.xaxis.set_major_formatter(ticker.FuncFormatter(mme))
fig.autofmt_xdate()
plt.show()
import numpy as np
import matplotlib.pyplot as plt
import pandas as p
file1=np.load('data/numofdays.npz')
fig,ax=plt.subplots(ncols=1)
y=np.array(file1['arr_0'])
mydates = p.DatetimeIndex(file1['arr_1'])
ax.bar(mydates,y, width=60)
fig.autofmt_xdate()
plt.show()