Skip to content

Commit 584153f

Browse files
author
Gorshanov Vadim
committed
Escape percents in legend and mm's in axis-label
1 parent 6b2c2ec commit 584153f

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/tikzplotlib/_axes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import matplotlib as mpl
22
import numpy as np
3+
import re
34
from matplotlib.backends.backend_pgf import (
45
common_texification as mpl_common_texification,
56
)
@@ -51,7 +52,7 @@ def __init__(self, data, obj): # noqa: C901
5152
xlabel = _common_texification(xlabel)
5253

5354
labelcolor = obj.xaxis.label.get_c()
54-
55+
xlabel = re.sub(r"\smm", r" \\si{\\mm}", xlabel)
5556
if labelcolor != "black":
5657
data, col, _ = _color.mpl_color2xcolor(data, labelcolor)
5758
self.axis_options.append(f"xlabel=\\textcolor{{{col}}}{{{xlabel}}}")

src/tikzplotlib/_line2d.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import datetime
22

33
import numpy as np
4+
import re
45
from matplotlib.dates import num2date
56

67
from . import _color as mycol
@@ -100,7 +101,8 @@ def draw_line2d(data, obj):
100101
content += c
101102

102103
if legend_text is not None:
103-
content.append(f"\\addlegendentry{{{legend_text}}}\n")
104+
legend_text_escaped = re.sub(r"(\d+(\.\d+)?)%", r"\\SI{\1}{\\percent}", legend_text)
105+
content.append(f"\\addlegendentry{{{legend_text_escaped}}}\n")
104106

105107
return data, content
106108

0 commit comments

Comments
 (0)