我有下面的函数(saveFigure),当我运行独立实例时x工作正常,其中x是时间的其他实例。
但是在一个python实例中如果我用x作为日期然后x作为时间调用此函数,我收到以下错误:
plt.savefig(param.location + os.sep + param.fileName + str(dim) + '.png')
File "C:\Anaconda\lib\site-packages\matplotlib\pyplot.py", line 472, in savefig
return fig.savefig(*args, **kwargs)
File "C:\Anaconda\lib\site-packages\matplotlib\figure.py", line 1370, in savefig
self.canvas.print_figure(*args, **kwargs)
File "C:\Anaconda\lib\site-packages\matplotlib\backends\backend_qt4agg.py", line 161, in print_figure
FigureCanvasAgg.print_figure(self, *args, **kwargs)
File "C:\Anaconda\lib\site-packages\matplotlib\backend_bases.py", line 2096, in print_figure
**kwargs)
File "C:\Anaconda\lib\site-packages\matplotlib\backends\backend_agg.py", line 492, in print_png
FigureCanvasAgg.draw(self)
File "C:\Anaconda\lib\site-packages\matplotlib\backends\backend_agg.py", line 440, in draw
self.figure.draw(self.renderer)
File "C:\Anaconda\lib\site-packages\matplotlib\artist.py", line 54, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\Anaconda\lib\site-packages\matplotlib\figure.py", line 1006, in draw
func(*args)
File "C:\Anaconda\lib\site-packages\matplotlib\artist.py", line 54, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\Anaconda\lib\site-packages\matplotlib\axes.py", line 2086, in draw
a.draw(renderer)
File "C:\Anaconda\lib\site-packages\matplotlib\artist.py", line 54, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\Anaconda\lib\site-packages\matplotlib\axis.py", line 1050, in draw
ticks_to_draw = self._update_ticks(renderer)
File "C:\Anaconda\lib\site-packages\matplotlib\axis.py", line 937, in _update_ticks
tick_tups = [t for t in self.iter_ticks()]
File "C:\Anaconda\lib\site-packages\matplotlib\axis.py", line 881, in iter_ticks
majorLocs = self.major.locator()
File "C:\Anaconda\lib\site-packages\matplotlib\ticker.py", line 897, in __call__
raise NotImplementedError('Derived must override')
NotImplementedError: Derived must override
def saveFigure(self, df, x, y, param, dim, timeBased):
ax = plt.subplot(111)
ax.bar(x, y)
if hasattr(param, 'title'):
ax.set_title(param.title)
if hasattr(param, 'ylabel'):
if hasattr(param.ylabel, '__iter__') and dim < len(param.ylabel):
ax.set_ylabel(param.ylabel[dim])
else:
ax.set_ylabel(param.ylabel)
if hasattr(param, 'xlabel'):
ax.set_xlabel(param.xlabel)
plt.gcf().autofmt_xdate()
plt.savefig(param.location + os.sep + param.fileName + str(dim) + '.png')