ValueError:视图限制最小值0.0小于1,并且是无效的Matplotlib日期值

时间:2018-11-02 10:38:09

标签: python numpy matplotlib data-science

我已经得到了使用matplotlib的python脚本,在运行脚本时它将打开窗口并显示图形。 它可以在我的笔记本电脑上正常工作。但是,当我在AWS Elasticbeanstalk上上传文件时,会发生此错误。 我通过使用

在笔记本电脑中成功重现了此错误
import matplotlib
matplotlib.use('agg')

引发的错误

File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/dates.py", line 1001, in viewlim_to_dt
.format(vmin))

这是该文件中的代码

def viewlim_to_dt(self):
    """
    Converts the view interval to datetime objects.
    """
    print(self.axis)
    vmin, vmax = self.axis.get_view_interval()
    if vmin > vmax:
        vmin, vmax = vmax, vmin
    if vmin < 1:
        raise ValueError('view limit minimum {} is less than 1 and '
                         'is an invalid Matplotlib date value. This '
                         'often happens if you pass a non-datetime '
                         'value to an axis that has datetime units'
                         .format(vmin))
    return num2date(vmin, self.tz), num2date(vmax, self.tz)

print(self.axis)显示此内容,然后引发错误

XAxis(100.000000,373.620690)

当我删除行matplotlib.use('agg')时,print(self.axis)显示

  

XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(200.000000,110.000000)   XAxis(59.111111,106.555556)   XAxis(59.111111,106.555556)   XAxis(59.111111,106.555556)   XAxis(59.111111,106.555556)   XAxis(59.111111,106.555556)   XAxis(59.111111,106.555556)   XAxis(59.111111,106.555556)   XAxis(59.111111,106.555556)   XAxis(59.111111,106.555556)   XAxis(59.111111,106.555556)   XAxis(59.111111,106.555556)   XAxis(59.111111,106.555556)   XAxis(59.111111,106.555556)   XAxis(59.111111,106.555556)   XAxis(59.111111,106.555556)   XAxis(59.111111,106.555556)   XAxis(59.111111,106.555556)   XAxis(59.111111,106.555556)   XAxis(59.111111,106.555556)   XAxis(59.111111,106.555556)   XAxis(225.000000,88.000000)   XAxis(225.000000,88.000000)   XAxis(225.000000,88.000000)   XAxis(225.000000,88.000000)   XAxis(225.000000,88.000000)   XAxis(225.000000,88.000000)   XAxis(225.000000,88.000000)   XAxis(225.000000,88.000000)   XAxis(225.000000,88.000000)   XAxis(225.000000,88.000000)   XAxis(225.000000,88.000000)   XAxis(225.000000,88.000000)   XAxis(225.000000,88.000000)   XAxis(225.000000,88.000000)   XAxis(225.000000,88.000000)   XAxis(225.000000,88.000000)   XAxis(225.000000,88.000000)   XAxis(225.000000,88.000000)   XAxis(225.000000,88.000000)   XAxis(225.000000,88.000000)   XAxis(225.000000,88.000000)   XAxis(225.000000,88.000000)   XAxis(225.000000,88.000000)   XAxis(225.000000,88.000000)   XAxis(122.930556,106.555556)   XAxis(122.930556,106.555556)   XAxis(122.930556,106.555556)   XAxis(122.930556,106.555556)

谁能帮助我,我不知道发生了什么。 我正在使用python3 这是我的完整进口

# -*- coding: utf-8 -*-
import numpy as np
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
import datetime
from matplotlib.dates import DateFormatter
from matplotlib.dates import HourLocator

这是完整的错误跟踪

File "/Users/abc/project/pythonfile.py", line 301, in plot_now
    facecolor='tab:purple', interpolate=True, alpha = 0.3, label='my_label')
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/__init__.py", line 1785, in inner
    return func(ax, *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/axes/_axes.py", line 5021, in fill_between
    self._process_unit_info(xdata=x, ydata=y1, kwargs=kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 2111, in _process_unit_info
    kwargs = _process_single_axis(xdata, self.xaxis, 'xunits', kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 2094, in _process_single_axis
    axis.update_units(data)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/axis.py", line 1478, in update_units
    self._update_axisinfo()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/axis.py", line 1496, in _update_axisinfo
    self.set_major_locator(info.majloc)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/axis.py", line 1617, in set_major_locator
    self.stale = True
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/artist.py", line 236, in stale
    self.stale_callback(self, val)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/artist.py", line 63, in _stale_axes_callback
    self.axes.stale = val
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/artist.py", line 236, in stale
    self.stale_callback(self, val)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/figure.py", line 57, in _stale_figure_callback
    self.figure.stale = val
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/artist.py", line 236, in stale
    self.stale_callback(self, val)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/pyplot.py", line 568, in _auto_draw_if_interactive
    fig.canvas.draw_idle()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/backend_bases.py", line 1899, in draw_idle
    self.draw(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py", line 402, in draw
    self.figure.draw(self.renderer)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/artist.py", line 50, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/figure.py", line 1652, in draw
    renderer, self, artists, self.suppressComposite)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/image.py", line 138, in _draw_list_compositing_images
    a.draw(renderer)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/artist.py", line 50, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 2604, in draw
    mimage._draw_list_compositing_images(renderer, self, artists)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/image.py", line 138, in _draw_list_compositing_images
    a.draw(renderer)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/artist.py", line 50, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/axis.py", line 1185, in draw
    ticks_to_draw = self._update_ticks(renderer)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/axis.py", line 1023, in _update_ticks
    tick_tups = list(self.iter_ticks())  # iter_ticks calls the locator
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/axis.py", line 967, in iter_ticks
    majorLocs = self.major.locator()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/dates.py", line 1230, in __call__
    self.refresh()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/dates.py", line 1250, in refresh
    dmin, dmax = self.viewlim_to_dt()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/dates.py", line 1001, in viewlim_to_dt
    .format(vmin))
ValueError: view limit minimum 0.0 is less than 1 and is an invalid Matplotlib date value. This often happens if you pass a non-datetime value to an axis that has datetime units

1 个答案:

答案 0 :(得分:0)

我已经解决了自己的问题,方法是在代码中将此行注释掉

plt.ion() 

正如我在问题中所说,该应用程序正在开发环境中(在笔记本电脑中)运行,但未在AWS服务器上运行。 希望对您有所帮助。