Skip to content

Complex LaTeX expressions in long_names aren't rendered correctly when plotting #5681

Closed
@tomchor

Description

@tomchor

What happened:

When I try to give a variable a long_name that's a complex latex expression and then plot that variable the expression doesn't get rendered by latex

What you expected to happen:

I expected the name to get rendered by latex

Minimal Complete Verifiable Example:

In the example below I'm plotting a variable with a complex long_name via xarray and then plotting it again (in a separate figure) using only matplotlib and manually setting xlabel(). The matplotlib-only version works fine (right), but the xarray version doesn't render (left).

import numpy as np
from matplotlib import pyplot as plt
import xarray as xr
da = xr.DataArray(range(5), dims="x", coords = dict(x=range(5)))
name = r"$Ra_s = \mathrm{mean}(\epsilon_k) / \mu M^2_\infty$"
da.x.attrs = dict(long_name = name)
da.plot()

plt.figure()
plt.plot(range(5))
plt.xlabel(name)

Screenshot from 2021-08-06 15-50-08

Anything else we need to know?:

Environment:

Output of xr.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.9.2 (default, Mar 3 2021, 20:02:32)
[GCC 7.3.0]
python-bits: 64
OS: Linux
OS-release: 5.10.53-1-MANJARO
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
libhdf5: 1.10.6
libnetcdf: 4.6.1

xarray: 0.17.0
pandas: 1.2.3
numpy: 1.19.2
scipy: 1.5.3
netCDF4: 1.5.6
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: 1.2.1
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: 1.3.2
dask: 2021.04.0
distributed: 2021.04.0
matplotlib: 3.3.4
cartopy: 0.18.0
seaborn: None
numbagg: None
pint: 0.17
setuptools: 52.0.0.post20210125
pip: 21.0.1
conda: None
pytest: None
IPython: 7.22.0
sphinx: None

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions