Skip to content

Certain unicode in Matplotlib + LaTeX #20262

@numpde

Description

@numpde

The following code fails at set_ylabel:

import matplotlib.pyplot as plt

with plt.style.context({'text.usetex': True}):
    (fig, ax) = plt.subplots()
    ax.set_xlabel("€")
    ax.set_ylabel("Δ")
    plt.show()

It works with $\Delta$ instead of Δ and it works if I unset text.usetex.

The generated tex is this:

\documentclass{article}
\newcommand{\mathdefault}[1]{#1}
\usepackage{type1cm}
\usepackage{type1ec}
\usepackage{type1ec}
\usepackage{type1ec}
\usepackage[utf8]{inputenc}
\DeclareUnicodeCharacter{2212}{\ensuremath{-}}
\usepackage[papersize=72in, margin=1in]{geometry}

\makeatletter\@ifpackageloaded{textcomp}{}{\usepackage{textcomp}}\makeatother
\pagestyle{empty}
\begin{document}
% The empty hbox ensures that a page is printed even for empty inputs, except
% when using psfrag which gets confused by it.
\fontsize{10.000000}{12.500000}%
\ifdefined\psfrag\else\hbox{}\fi%
{\sffamily Δ}
\end{document}

and it compiles fine with pdflatex if I replace \usepackage[utf8]{inputenc} by \usepackage[utf8x]{inputenc}. Otherwise the error is the same:

! Package inputenc Error: Unicode character Δ (U+0394)
(inputenc)                not set up for use with LaTeX.

I think this is on the side of unexpected behavior.

Versions: Python 3.8.5 and matplotlib==3.4.1.

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy