首页 > 解决方案 > matplotlib 删除 IndexError: tuple index out of range after upgrade

问题描述

我在升级 Python 库时犯了一个错误,现在 matplotlib 出现以下错误:

IndexError:元组索引超出范围

在昨天工作的一个非常简单的代码上。

考虑一下我昨天绘制的这个大 CSV 文件:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

headers = ['fx', 'fy', 'fz', 'tx', 'ty', 'tz', 'currentr',
           'time', 'theta', 'omegay', 'currenty', 'pr', 'Dc', 'Fr', 'Fl']
df = pd.read_csv('20190802_pase3part1_test3PC-c156.csv', names=headers)

fig3 = plt.figure()
plt.plot(df.index, df['time'])
plt.show()

但升级后我收到错误:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-5-1ce3610bc7d8> in <module>
      1 fig3 = plt.figure()
----> 2 plt.plot(df.index, df['time'])
      3 plt.show()

c:\python37\lib\site-packages\matplotlib\pyplot.py in plot(scalex, scaley, data, *args, **kwargs)
   2793     return gca().plot(
   2794         *args, scalex=scalex, scaley=scaley, **({"data": data} if data
-> 2795         is not None else {}), **kwargs)
   2796 
   2797 

c:\python37\lib\site-packages\matplotlib\axes\_axes.py in plot(self, scalex, scaley, data, *args, **kwargs)
   1664         """
   1665         kwargs = cbook.normalize_kwargs(kwargs, mlines.Line2D._alias_map)
-> 1666         lines = [*self._get_lines(*args, data=data, **kwargs)]
   1667         for line in lines:
   1668             self.add_line(line)

c:\python37\lib\site-packages\matplotlib\axes\_base.py in __call__(self, *args, **kwargs)
    223                 this += args[0],
    224                 args = args[1:]
--> 225             yield from self._plot_args(this, kwargs)
    226 
    227     def get_next_color(self):

c:\python37\lib\site-packages\matplotlib\axes\_base.py in _plot_args(self, tup, kwargs)
    397             func = self._makefill
    398 
--> 399         ncx, ncy = x.shape[1], y.shape[1]
    400         if ncx > 1 and ncy > 1 and ncx != ncy:
    401             cbook.warn_deprecated(

IndexError: tuple index out of range

我认为这是一个错误,但我不知道是什么原因造成的。

我的环境是:

如果您能帮助我了解问题所在以及如何解决,我将不胜感激?

PS1。我刚刚在另一台使用 matplotlib 的计算机上尝试了代码3.0.3,它就成功了!

PS2。在这里发出一个错误

PS3。我刚刚尝试通过以下方式降级到以前的版本:

pip uninstall matplotlib
pip install matplotlib==<version>

但它没有用!

PS4。好的,事实证明这是一个熊猫错误。降级0.25解决0.24问题!(详情

标签: pythonpandasmatplotlibplot

解决方案


推荐阅读