我试图在Zeppelin中绘制时间序列数据,但是我的绘图函数的每次交替运行都会得到ValueError。
以下是示例代码:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
rng = pd.date_range('1/1/2000', periods=10, freq='M')
ts = pd.Series(np.random.randn(len(rng)), index=rng)
# Plotting the data:
orig = plt.plot(ts)
plt.show()
首次运行此代码会产生ValueError: ordinal must be >= 1
,但是当我再次运行代码(在同一单元格中)时会出现该图。但错误在第三次运行中再次返回,依此类推。这是追溯:
Traceback (most recent call last):
File "/tmp/zeppelin_python-2526037595738258825.py", line 282, in <module>
raise Exception(traceback.format_exc())
Exception: Traceback (most recent call last):
File "/tmp/zeppelin_python-2526037595738258825.py", line 275, in <module>
exec(code, _zcUserQueryNameSpace)
File "<stdin>", line 1, in <module>
File "build/bdist.linux-x86_64/egg/flytxt_libs/forecasting/time_series.py", line 37, in stationarity_test
orig = plt.plot(timeseries, color='blue', label='Original')
File "/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py", line 3318, in plot
ret = ax.plot(*args, **kwargs)
File "/usr/lib64/python2.7/site-packages/matplotlib/__init__.py", line 1892, in inner
return func(ax, *args, **kwargs)
File "/usr/lib64/python2.7/site-packages/matplotlib/axes/_axes.py", line 1406, in plot
for line in self._get_lines(*args, **kwargs):
File "/usr/lib64/python2.7/site-packages/matplotlib/axes/_base.py", line 407, in _grab_next_args
for seg in self._plot_args(remaining, kwargs):
File "/usr/lib64/python2.7/site-packages/matplotlib/axes/_base.py", line 385, in _plot_args
x, y = self._xy_from_xy(x, y)
File "/usr/lib64/python2.7/site-packages/matplotlib/axes/_base.py", line 217, in _xy_from_xy
bx = self.axes.xaxis.update_units(x)
File "/usr/lib64/python2.7/site-packages/matplotlib/axis.py", line 1424, in update_units
self._update_axisinfo()
File "/usr/lib64/python2.7/site-packages/matplotlib/axis.py", line 1442, in _update_axisinfo
self.set_major_locator(info.majloc)
File "/usr/lib64/python2.7/site-packages/matplotlib/axis.py", line 1543, in set_major_locator
self.stale = True
File "/usr/lib64/python2.7/site-packages/matplotlib/artist.py", line 279, in stale
self.stale_callback(self, val)
File "/usr/lib64/python2.7/site-packages/matplotlib/artist.py", line 76, in _stale_axes_callback
self.axes.stale = val
File "/usr/lib64/python2.7/site-packages/matplotlib/artist.py", line 279, in stale
self.stale_callback(self, val)
File "/usr/lib64/python2.7/site-packages/matplotlib/figure.py", line 56, in _stale_figure_callback
self.figure.stale = val
File "/usr/lib64/python2.7/site-packages/matplotlib/artist.py", line 279, in stale
self.stale_callback(self, val)
File "/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py", line 576, in _auto_draw_if_interactive
fig.canvas.draw_idle()
File "/usr/local/zeppelin/interpreter/lib/python/backend_zinline.py", line 136, in draw_idle
self.draw(*args, **kwargs)
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 464, in draw
self.figure.draw(self.renderer)
File "/usr/lib64/python2.7/site-packages/matplotlib/artist.py", line 63, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib64/python2.7/site-packages/matplotlib/figure.py", line 1143, in draw
renderer, self, dsu, self.suppressComposite)
File "/usr/lib64/python2.7/site-packages/matplotlib/image.py", line 139, in _draw_list_compositing_images
a.draw(renderer)
File "/usr/lib64/python2.7/site-packages/matplotlib/artist.py", line 63, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib64/python2.7/site-packages/matplotlib/axes/_base.py", line 2409, in draw
mimage._draw_list_compositing_images(renderer, self, dsu)
File "/usr/lib64/python2.7/site-packages/matplotlib/image.py", line 139, in _draw_list_compositing_images
a.draw(renderer)
File "/usr/lib64/python2.7/site-packages/matplotlib/artist.py", line 63, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib64/python2.7/site-packages/matplotlib/axis.py", line 1136, in draw
ticks_to_draw = self._update_ticks(renderer)
File "/usr/lib64/python2.7/site-packages/matplotlib/axis.py", line 969, in _update_ticks
tick_tups = [t for t in self.iter_ticks()]
File "/usr/lib64/python2.7/site-packages/matplotlib/axis.py", line 912, in iter_ticks
majorLocs = self.major.locator()
File "/usr/lib64/python2.7/site-packages/matplotlib/dates.py", line 983, in __call__
self.refresh()
File "/usr/lib64/python2.7/site-packages/matplotlib/dates.py", line 1003, in refresh
dmin, dmax = self.viewlim_to_dt()
File "/usr/lib64/python2.7/site-packages/matplotlib/dates.py", line 760, in viewlim_to_dt
return num2date(vmin, self.tz), num2date(vmax, self.tz)
File "/usr/lib64/python2.7/site-packages/matplotlib/dates.py", line 401, in num2date
return _from_ordinalf(x, tz)
File "/usr/lib64/python2.7/site-packages/matplotlib/dates.py", line 254, in _from_ordinalf
dt = datetime.datetime.fromordinal(ix).replace(tzinfo=UTC)
ValueError: ordinal must be >= 1
有趣的是,相同的代码在Jupyter笔记本5.3.1中运行良好,没有任何此类问题。
我的Zeppelin版本是0.7.2,matplotlib版本是2.0.0。
有人可以告诉我为什么会这样吗?