Skip to content
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

TickLabels.simplify_labels corrupts LaTeX label strings on Mollweide axes #8004

Closed
lpsinger opened this issue Oct 27, 2018 · 0 comments · Fixed by #9991
Closed

TickLabels.simplify_labels corrupts LaTeX label strings on Mollweide axes #8004

lpsinger opened this issue Oct 27, 2018 · 0 comments · Fixed by #9991

Comments

@lpsinger
Copy link
Contributor

This example script that makes a Mollweide projection plot with WCSAxes with matplotlib's text.usetex rcparam set to True crashes. By setting breakpoints, I found that it is the declination axis that is getting corrupted, and it is happening in TickLabels.simplify_labels.

test.py

#!/usr/bin/env python
import matplotlib
matplotlib.rcParams['text.usetex'] = True
from astropy import units as u
from astropy.visualization.wcsaxes.frame import EllipticalFrame
from astropy.wcs import WCS
from matplotlib import pyplot as plt
import numpy as np

header = {
    'NAXIS': 2,
    'NAXIS1': 360,
    'NAXIS2': 180,
    'CRPIX1': 180.5,
    'CRPIX2': 90.5,
    'CRVAL1': 180.0,
    'CRVAL2': 0.0,
    'CDELT1': -2 * np.sqrt(2) / np.pi,
    'CDELT2': 2 * np.sqrt(2) / np.pi,
    'CTYPE1': 'RA---MOL',
    'CTYPE2': 'DEC--MOL',
    'RADESYS': 'ICRS'}

wcs = WCS(header)
ax = plt.axes(frame_class=EllipticalFrame, projection=wcs)
ax.set_xlim(-0.5, header['NAXIS1'] - 0.5)
ax.set_ylim(-0.5, header['NAXIS2'] - 0.5)
ax.coords[0].set_ticks(exclude_overlapping=True, spacing=45 * u.deg)
ax.coords[1].set_ticks(exclude_overlapping=True, spacing=30 * u.deg)
ax.grid()
plt.savefig('test.png')

Output

$ ./test.py 
Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/texmanager.py", line 298, in _run_checked_subprocess
    stderr=subprocess.STDOUT)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 389, in check_output
    **kwargs).stdout
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 481, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['latex', '-interaction=nonstopmode', '--halt-on-error', '/Users/lpsinger/.matplotlib/tex.cache/3a1d4a91ea3bce281dc11a6a0700d7e5.tex']' returned non-zero exit status 1.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./test.py", line 31, in <module>
    plt.savefig('test.png')
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/pyplot.py", line 688, in savefig
    res = fig.savefig(*args, **kwargs)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/figure.py", line 2097, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/backend_bases.py", line 2075, in print_figure
    **kwargs)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/backends/backend_agg.py", line 510, in print_png
    FigureCanvasAgg.draw(self)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/backends/backend_agg.py", line 402, in draw
    self.figure.draw(self.renderer)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/artist.py", line 50, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/figure.py", line 1652, in draw
    renderer, self, artists, self.suppressComposite)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/image.py", line 138, in _draw_list_compositing_images
    a.draw(renderer)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/astropy/visualization/wcsaxes/core.py", line 392, in draw
    super().draw(renderer, inframe=inframe)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/artist.py", line 50, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/axes/_base.py", line 2604, in draw
    mimage._draw_list_compositing_images(renderer, self, artists)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/image.py", line 138, in _draw_list_compositing_images
    a.draw(renderer)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/astropy/visualization/wcsaxes/core.py", line 48, in draw
    self.axes.draw_wcsaxes(renderer)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/astropy/visualization/wcsaxes/core.py", line 356, in draw_wcsaxes
    ticks_locs=ticks_locs[coord])
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/astropy/visualization/wcsaxes/coordinate_helpers.py", line 483, in _draw_ticks
    ticklabels_bbox=ticklabels_bbox)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/astropy/visualization/wcsaxes/ticklabels.py", line 157, in draw
    bb = super().get_window_extent(renderer)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/text.py", line 929, in get_window_extent
    bbox, info, descent = self._get_layout(self._renderer)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/text.py", line 313, in _get_layout
    ismath=ismath)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/backends/backend_agg.py", line 209, in get_text_width_height_descent
    s, fontsize, renderer=self)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/texmanager.py", line 464, in get_text_width_height_descent
    dvifile = self.make_dvi(tex, fontsize)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/texmanager.py", line 328, in make_dvi
    texfile], tex)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/texmanager.py", line 307, in _run_checked_subprocess
    exc=exc.output.decode('utf-8')))
RuntimeError: latex was not able to process the following string:
b'$'

Here is the full report generated by latex:
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018/MacPorts 2018.47642_7) (preloaded format=latex)
 restricted \write18 enabled.
entering extended mode
(/Users/lpsinger/.matplotlib/tex.cache/3a1d4a91ea3bce281dc11a6a0700d7e5.tex
LaTeX2e <2018-04-01> patch level 2
Babel <3.18> and hyphenation patterns for 46 language(s) loaded.
(/opt/local/share/texmf-texlive/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/opt/local/share/texmf-texlive/tex/latex/base/size10.clo))
(/opt/local/share/texmf-texlive/tex/latex/type1cm/type1cm.sty)
(/opt/local/share/texmf-texlive/tex/latex/base/textcomp.sty
(/opt/local/share/texmf-texlive/tex/latex/base/ts1enc.def
(/opt/local/share/texmf-texlive/tex/latex/base/ts1enc.dfu)))
(/opt/local/share/texmf-texlive/tex/latex/base/inputenc.sty)
(/opt/local/share/texmf-texlive/tex/latex/geometry/geometry.sty
(/opt/local/share/texmf-texlive/tex/latex/graphics/keyval.sty)
(/opt/local/share/texmf-texlive/tex/generic/oberdiek/ifpdf.sty)
(/opt/local/share/texmf-texlive/tex/generic/oberdiek/ifvtex.sty)
(/opt/local/share/texmf-texlive/tex/generic/ifxetex/ifxetex.sty)

Package geometry Warning: Over-specification in `h'-direction.
    `width' (5058.9pt) is ignored.


Package geometry Warning: Over-specification in `v'-direction.
    `height' (5058.9pt) is ignored.

) (./3a1d4a91ea3bce281dc11a6a0700d7e5.aux)
(/opt/local/share/texmf-texlive/tex/latex/base/ts1cmr.fd)
*geometry* driver: auto-detecting
*geometry* detected driver: dvips
! Extra }, or forgotten $.
<recently read> }
                 
l.14 \fontsize{10.000000}{12.500000}{\sffamily $}
                                                 
No pages of output.
Transcript written on 3a1d4a91ea3bce281dc11a6a0700d7e5.log.
lpsinger added a commit to lpsinger/gwcelery that referenced this issue Dec 19, 2018
lpsinger added a commit to lpsinger/astropy that referenced this issue Feb 27, 2020
lpsinger added a commit to lpsinger/astropy that referenced this issue Feb 27, 2020
lpsinger added a commit to lpsinger/astropy that referenced this issue Mar 12, 2020
lpsinger added a commit to lpsinger/astropy that referenced this issue Mar 12, 2020
lpsinger added a commit to lpsinger/astropy that referenced this issue Mar 12, 2020
lpsinger added a commit to lpsinger/astropy that referenced this issue Mar 12, 2020
lpsinger added a commit to lpsinger/astropy that referenced this issue Mar 12, 2020
lpsinger added a commit to lpsinger/astropy that referenced this issue Mar 12, 2020
lpsinger added a commit to lpsinger/astropy that referenced this issue Mar 12, 2020
lpsinger added a commit to lpsinger/astropy that referenced this issue Mar 19, 2020
lpsinger added a commit to lpsinger/astropy that referenced this issue Mar 19, 2020
lpsinger added a commit to lpsinger/astropy that referenced this issue Mar 19, 2020
lpsinger added a commit to lpsinger/gwcelery that referenced this issue Jan 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants