Skip to content

matplotlib.axes.Axes.indicate_inset default label value is incompatible with LaTeX #19372

Closed
@rkevk

Description

@rkevk

Bug report

Bug summary

If matplotlib.axes.Axes.indicate_inset is called without specifying the label kwarg, then it sets indicate_inset as a default value (as per the source). If it does so while mpl.rc('text', usetex=True) is set and also creating a legend, LaTeX attempts to typeset the label indicate_inset, but fails due to the unescaped underscore. A solution is to pass label='' to indicate_inset, which should possibly be the new default.

Code for reproduction

import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.rc('text', usetex=True)

fig, ax = plt.subplots(1,1)
axins   = ax.inset_axes([0.25, 0.65, 0.3, 0.3])
ax.indicate_inset_zoom(axins)
ax.legend(loc='best')
plt.show()

Actual outcome
A typical long LaTeX callback list, the relevant snippets are:

.
.
.
  File "/usr/lib/python3/dist-packages/matplotlib/texmanager.py", line 310, in _run_checked_subprocess
    raise RuntimeError(
RuntimeError: latex was not able to process the following string:
b'indicate_inset'
.
.
.
! Missing $ inserted.
<inserted text> 
                $
l.14 ...{10.000000}{12.500000}{\sffamily indicate_
                                                  inset}
No pages of output.
.
.
.

Matplotlib version

  • Operating system: Ubuntu 20.04.1LTS, kernel version 5.4.0-62-generic
  • Matplotlib version 3.1.2
  • Matplotlib backend TkAgg:
  • Python version: 3.8.5
  • Other libraries: irrelevant

python and matplotlib both installed from official ubuntu repositories

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions