【问题标题】:KeyError when trying to plot matplotlib subplots after update更新后尝试绘制 matplotlib 子图时出现 KeyError
【发布时间】:2023-03-12 09:28:01
【问题描述】:

在最近的 ubuntu 更新之后,我不能再在 matplotlib 中绘制子图了。不完全确定更新了什么并导致此问题。我的版本是 ubuntu 17.04、matplotlib 2.0.0、python 2.7。有谁知道可能是什么原因?

我只是尝试过:

from matplotlib import pyplot as plt
fig, axs = plt.subplots(3,3)

导致:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 1212, in subplots
    ax0 = fig.add_subplot(gs[0, 0], **subplot_kw)
  File "/usr/lib/python2.7/dist-packages/matplotlib/figure.py", line 1020, in add_subplot
    a = subplot_class_factory(projection_class)(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/matplotlib/axes/_subplots.py", line 73, in __init__
    self._axes_class.__init__(self, fig, self.figbox, **kwargs)
  File "/usr/lib/python2.7/dist-packages/matplotlib/axes/_base.py", line 529, in __init__
    self._init_axis()
  File "/usr/lib/python2.7/dist-packages/matplotlib/axes/_base.py", line 625, in _init_axis
    self.yaxis = maxis.YAxis(self)
  File "/usr/lib/python2.7/dist-packages/matplotlib/axis.py", line 676, in __init__
    self.cla()
  File "/usr/lib/python2.7/dist-packages/matplotlib/axis.py", line 760, in cla
    self.reset_ticks()
  File "/usr/lib/python2.7/dist-packages/matplotlib/axis.py", line 774, in reset_ticks
    self.majorTicks.extend([self._get_tick(major=True)])
  File "/usr/lib/python2.7/dist-packages/matplotlib/axis.py", line 2057, in _get_tick
    return YTick(self.axes, 0, '', major=major, **tick_kw)
  File "/usr/lib/python2.7/dist-packages/matplotlib/axis.py", line 148, in __init__
    self.apply_tickdir(tickdir)
  File "/usr/lib/python2.7/dist-packages/matplotlib/axis.py", line 512, in apply_tickdir
    self._pad = self._base_pad + self.get_tick_padding()
  File "/usr/lib/python2.7/dist-packages/matplotlib/axis.py", line 184, in get_tick_padding
    return self._size * padding[self._tickdir]
KeyError: u'our

【问题讨论】:

  • 我想很难找出是什么原因造成的,所以可能需要重新安装 matplotlib。

标签: python matplotlib subplot keyerror ubuntu-17.04


【解决方案1】:

成功了!谢谢ImportanceOfBeingErnest :) 我做到了:

sudo -H pip uninstall matplotlib
sudo -H pip install matplotlib

现在它又可以工作了。

【讨论】:

    猜你喜欢
    • 2016-03-11
    • 1970-01-01
    • 2018-09-08
    • 1970-01-01
    • 1970-01-01
    • 2020-05-25
    • 1970-01-01
    • 1970-01-01
    • 2020-12-27
    相关资源
    最近更新 更多