8000 table.table fails with KeyError (legacy python and mpl 2.2.0 only) · Issue #10740 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
table.table fails with KeyError (legacy python and mpl 2.2.0 only) #10740
Closed
@TomAugspurger

Description

@TomAugspurger

Bug report

Bug summary

In matplotlib 2.2 with python 2.7, the following code raises a KeyError. It succeeded in 1.5.3

Code for reproduction

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


fig, ax = plt.subplots()
data = np.random.randn(10, 3)
rowLabels = list('abcdefghij')
colLabels = [0, 1, 2]

table = matplotlib.table.table(ax, cellText=data.T, rowLabels=colLabels,
                               colLabels=rowLabels)
fig.savefig('foo.png')

Actual outcome

Traceback (most recent call last):
  File "foo.py", line 14, in <module>
    fig.savefig('foo.png')
  File "/Users/taugspurger/Envs/py27/lib/python2.7/site-packages/matplotlib/figure.py", line 2035, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File "/Users/taugspurger/Envs/py27/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 2261, in print_figure
    **kwargs)
  File "/Users/taugspurger/Envs/py27/lib/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 511, in print_png
    FigureCanvasAgg.draw(self)
  File "/Users/taugspurger/Envs/py27/lib/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 431, in draw
    self.figure.draw(self.renderer)
  File "/Users/taugspurger/Envs/py27/lib/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/Users/taugspurger/Envs/py27/lib/python2.7/site-packages/matplotlib/figure.py", line 1475, in draw
    renderer, self, artists, self.suppressComposite)
  File "/Users/taugspurger/Envs/py27/lib/python2.7/site-packages/matplotlib/image.py", line 141, in _draw_list_compositing_images
    a.draw(renderer)
  File "/Users/taugspurger/Envs/py27/lib/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/Users/taugspurger/Envs/py27/lib/python2.7/site-packages/matplotlib/axes/_base.py", line 2607, in draw
    mimage._draw_list_compositing_images(renderer, self, artists)
  File "/Users/taugspurger/Envs/py27/lib/python2.7/site-packages/matplotlib/image.py", line 
6C8F
141, in _draw_list_compositing_images
    a.draw(renderer)
  File "/Users/taugspurger/Envs/py27/lib/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/Users/taugspurger/Envs/py27/lib/python2.7/site-packages/matplotlib/table.py", line 350, in draw
    self._update_positions(renderer)
  File "/Users/taugspurger/Envs/py27/lib/python2.7/site-packages/matplotlib/table.py", line 536, in _update_positions
    self._auto_set_font_size(renderer)
  File "/Users/taugspurger/Envs/py27/lib/python2.7/site-packages/matplotlib/table.py", line 494, in _auto_set_font_size
    size = cell.auto_set_font_size(renderer)
  File "/Users/taugspurger/Envs/py27/lib/python2.7/site-packages/matplotlib/table.py", line 95, in auto_set_font_size
    required = self.get_required_width(renderer)
  File "/Users/taugspurger/Envs/py27/lib/python2.7/site-packages/matplotlib/table.py", line 144, in get_required_width
    l, b, w, h = self.get_text_bounds(renderer)
  File "/Users/taugspurger/Envs/py27/lib/python2.7/site-packages/matplotlib/table.py", line 138, in get_text_bounds
    bbox = self._text.get_window_extent(renderer)
  File "/Users/taugspurger/Envs/py27/lib/python2.7/site-packages/matplotlib/text.py", line 922, in get_window_extent
    bbox, info, descent = self._get_layout(self._renderer)
  File "/Users/taugspurger/Envs/py27/lib/python2.7/site-packages/matplotlib/text.py", line 300, in _get_layout
    ismath=False)
  File "/Users/taugspurger/Envs/py27/lib/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 239, in get_text_width_height_descent
    font = self._get_agg_font(prop)
  File "/Users/taugspurger/Envs/py27/lib/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 273, in _get_agg_font
    fname = findfont(prop)
  File "/Users/taugspurger/Envs/py27/lib/python2.7/site-packages/matplotlib/font_manager.py", line 1475, in findfont
    font = fontManager.findfont(prop, **kw)
  File "/Users/taugspurger/Envs/py27/lib/python2.7/site-packages/matplotlib/font_manager.py", line 1290, in findfont
    rc_params)
  File "/Users/taugspurger/Envs/py27/lib/python2.7/site-packages/backports/functools_lru_cache.py", line 156, in wrapper
    del cache[oldkey]
KeyError: (<matplotlib.font_manager.FontManager object at 0x107661250>, <matplotlib.font_manager.FontProperties object at 0x10c3a11d0>, 'ttf', None, True, True, (('DejaVu Serif', 'Bitstream Vera Serif', 'Computer Modern Roman', 'New Century Schoolbook', 'Century Schoolbook L', 'Utopia', 'ITC Bookman', 'Bookman', 'Nimbus Roman No9 L', 'Times New Roman', 'Times', 'Palatino', 'Charter', 'serif'), ('DejaVu Sans', 'Bitstream Vera Sans', 'Computer Modern Sans Serif', 'Lucida Grande', 'Verdana', 'Geneva', 'Lucid', 'Arial', 'Helvetica', 'Avant Garde', 'sans-serif'), ('Apple Chancery', 'Textile', 'Zapf Chancery', 'Sand', 'Script MT', 'Felipa', 'cursive'), ('Comic Sans MS', 'Chicago', 'Charcoal', 'ImpactWestern', 'Humor Sans', 'xkcd', 'fantasy'), ('DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Computer Modern Typewriter', 'Andale Mono', 'Nimbus Mono L', 'Courier New', 'Courier', 'Fixed', 'Terminal', 'monospace')))

Expected outcome

Same as mpl 2.2

Matplotlib version

  • Operating system: MacOS 10.13.3
  • Matplotlib version: 2.2.0
  • Matplotlib backend: TkAgg
  • Python version: 2.7 (works correctly with 3.6)

Installed from wheels of PyPI.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0