Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rkevk opened this issue Jan 27, 2021 · 2 comments · Fixed by #19378
Closed

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

rkevk opened this issue Jan 27, 2021 · 2 comments · Fixed by #19378
Milestone

Comments

@rkevk
Copy link

rkevk commented Jan 27, 2021

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

@rkevk
Copy link
Author

rkevk commented Jan 27, 2021

(Of course this also applies to indicate_inset_zoom as indicated here, which passes arguments to indicate_inset.)

@jklymak
Copy link
Member

jklymak commented Jan 27, 2021

Ooops, guess we never tested with a legend (I assume it makes a spurious legend entry regardless of usetex?)

I agree that this should be fixed and that there should be no label (presumably by default). I guess I was thinking of the label as a way of differentiating it from data. One alternative is to change the label to _indicate_inset which will not get a legend entry I believe. Any interest in tackling this? (Developers guide: https://matplotlib.org/stable/devel/index.html)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants