@@ -12,6 +12,16 @@ def _common_texification(string):
12
12
# Work around <https://github.com/matplotlib/matplotlib/issues/15493>
13
13
return mpl_common_texification (string ).replace ("&" , "\\ &" )
14
14
15
+ def _siunitx_texification (string : str ) -> str :
16
+ string = re .sub (r"\smm" , r" \\si{\\mm}" , string )
17
+ string = re .sub (r"\s°C" , r" \\si{\\celsius}" , string )
18
+ string = re .sub (r"\sA/s" , r" \\si{\\angstrom\\per\\second}" , string )
19
+ string = re .sub (r"\sg/s" , r" \\si{\\gram\\per\\second}" , string )
20
+ string = re .sub (r"\shour" , r" \\si{\\hour}" , string )
21
+ string = re .sub (r"\scc" , r" \\si{\\cc}" , string )
22
+ string = re .sub (r"\s\\%" , r" \\si{\\percent}" , string )
23
+ return string
24
+
15
25
16
26
class Axes :
17
27
def __init__ (self , data , obj ): # noqa: C901
@@ -50,9 +60,9 @@ def __init__(self, data, obj): # noqa: C901
50
60
xlabel = obj .get_xlabel ()
51
61
if xlabel :
52
62
xlabel = _common_texification (xlabel )
63
+ xlabel = _siunitx_texification (xlabel )
53
64
54
65
labelcolor = obj .xaxis .label .get_c ()
55
- xlabel = re .sub (r"\smm" , r" \\si{\\mm}" , xlabel )
56
66
xlabel_spl = xlabel .split ("," )
57
67
if len (xlabel_spl ) == 2 :
58
68
xlabel = "," .join (["$" + xlabel_spl [0 ].replace (" " , "\\ " ) + "$" ,
@@ -71,10 +81,13 @@ def __init__(self, data, obj): # noqa: C901
71
81
ylabel = obj .get_ylabel ()
72
82
if ylabel :
73
83
ylabel = _common_texification (ylabel )
84
+ ylabel = _siunitx_texification (ylabel )
74
85
75
86
ylabel_spl = ylabel .split ("," )
76
87
if len (ylabel_spl ) == 2 :
77
- ylabel = "," .join (["$" + ylabel_spl [0 ].replace (" " , "\\ " ) + "$" ,
88
+ ylabel = "," .join (["$" + ylabel_spl [0 ].replace (" " ,
89
+ "\\ " ).replace ("+-" , r"\pm" ).replace ("-" ,
90
+ r"\mhyphen " ) + "$" ,
78
91
ylabel_spl [1 ]])
79
92
80
93
labelcolor = obj .yaxis .label .get_c ()
0 commit comments