Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
In presence of row and column labels, the cell indexing by the Table class is inconsistent: column labels have row index 0, but row labels have column index -1:
from pylab import *gca().set_axis_off()t = table( cellText=[["a", "b"], ["c", "d"]], rowLabels=["row1", "row2"], colLabels=["col1", "col2"],)for (i, j), cell in sorted(t.get_celld().items()): print(i, j, cell.get_text())show()
gives
0 0 Text(0, 0, 'col1')0 1 Text(0, 0, 'col2')1 -1 Text(0, 0, 'row1')1 0 Text(0, 0, 'a')1 1 Text(0, 0, 'b')2 -1 Text(0, 0, 'row2')2 0 Text(0, 0, 'c')2 1 Text(0, 0, 'd')
As an example of bug caused by this API, thetext_labels_and_annotations/font_table_ttf_sfskip.py
example contains the seemingly innocuous code
if row > 0 and col > 0: cell.set_text_props(fontproperties=FontProperties(fname=fontname))
but running the example, passing a local font pathname as argument (e.g.python examples/text_labels_and_annotations/font_table_ttf_sgskip.py lib/matplotlib/mpl-data/fonts/ttf/cmr10.ttf
from the mpl root directory) shows that the first column of characters is not using the correct font.
Indeed, the correct code would have been
if row > 0 and col > -1: cell.set_text_props(fontproperties=FontProperties(fname=fontname))
I think the inconsistency is error-prone enough to consider changing it (probably handling the deprecations depending on the value of a global switch).