Skip to content

fix #559 for matplotlib >= 3.6 #602

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/tikzplotlib/_axes.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import matplotlib as mpl
import numpy as np
from matplotlib.backends.backend_pgf import (
common_texification as mpl_common_texification,
)
from matplotlib.backends.backend_pgf import _tex_escape as mpl_tex_escape

from . import _color


def _common_texification(string):
def _tex_escape(string):
# Work around <https://github.com/matplotlib/matplotlib/issues/15493>
return mpl_common_texification(string).replace("&", "\\&")
return mpl_tex_escape(string).replace("&", "\\&")


class Axes:
Expand Down Expand Up @@ -42,13 +40,13 @@ def __init__(self, data, obj): # noqa: C901
title = obj.get_title()
data["current axis title"] = title
if title:
title = _common_texification(title)
title = _tex_escape(title)
self.axis_options.append(f"title={{{title}}}")

# get axes titles
xlabel = obj.get_xlabel()
if xlabel:
xlabel = _common_texification(xlabel)
xlabel = _tex_escape(xlabel)

labelcolor = obj.xaxis.label.get_c()

Expand All @@ -64,7 +62,7 @@ def __init__(self, data, obj): # noqa: C901

ylabel = obj.get_ylabel()
if ylabel:
ylabel = _common_texification(ylabel)
ylabel = _tex_escape(ylabel)

labelcolor = obj.yaxis.label.get_c()
if labelcolor != "black":
Expand Down Expand Up @@ -594,7 +592,7 @@ def _get_ticks(data, xy, ticks, ticklabels):
label = ticklabel.get_text()
if "," in label:
label = "{" + label + "}"
pgfplots_ticklabels.append(_common_texification(label))
pgfplots_ticklabels.append(_tex_escape(label))

# note: ticks may be present even if labels are not, keep them for grid lines
for tick in ticks:
Expand Down