1
1
import matplotlib as mpl
2
2
import numpy
3
- from matplotlib .backends import backend_pgf as mpl_backend_pgf
3
+ from matplotlib .backends . backend_pgf import common_texification as mpl_common_texification
4
4
5
5
from . import color
6
6
7
7
8
+ def _common_texification (string ):
9
+ return mpl_common_texification (string ).replace ("&" , "\\ &" )
10
+
11
+
8
12
class Axes :
9
13
def __init__ (self , data , obj ): # noqa: C901
10
14
"""Returns the PGFPlots code for an axis environment.
@@ -36,14 +40,14 @@ def __init__(self, data, obj): # noqa: C901
36
40
title = obj .get_title ()
37
41
data ["current axis title" ] = title
38
42
if title :
39
- title = mpl_backend_pgf . common_texification (title )
43
+ title = _common_texification (title )
40
44
self .axis_options .append (u"title={{{}}}" .format (title ))
41
45
42
46
# get axes titles
43
47
xlabel = obj .get_xlabel ()
44
48
xrotation = obj .xaxis .get_label ().get_rotation ()
45
49
if xlabel :
46
- xlabel = mpl_backend_pgf . common_texification (xlabel )
50
+ xlabel = _common_texification (xlabel )
47
51
self .axis_options .append (u"xlabel={{{}}}" .format (xlabel ))
48
52
if xrotation != 0 :
49
53
self .axis_options .append (
@@ -52,7 +56,7 @@ def __init__(self, data, obj): # noqa: C901
52
56
ylabel = obj .get_ylabel ()
53
57
yrotation = obj .yaxis .get_label ().get_rotation ()
54
58
if ylabel :
55
- ylabel = mpl_backend_pgf . common_texification (ylabel )
59
+ ylabel = _common_texification (ylabel )
56
60
self .axis_options .append (u"ylabel={{{}}}" .format (ylabel ))
57
61
if yrotation != 90 :
58
62
self .axis_options .append (
@@ -559,7 +563,7 @@ def _get_ticks(data, xy, ticks, ticklabels):
559
563
# store the label anyway
560
564
label = ticklabel .get_text ()
561
565
if ticklabel .get_visible ():
562
- label = mpl_backend_pgf . common_texification (label )
566
+ label = _common_texification (label )
563
567
pgfplots_ticklabels .append (label )
564
568
else :
565
569
is_label_required = True
0 commit comments