11import matplotlib as mpl
22import 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
44
55from . import color
66
77
8+ def _common_texification (string ):
9+ return mpl_common_texification (string ).replace ("&" , "\\ &" )
10+
11+
812class Axes :
913 def __init__ (self , data , obj ): # noqa: C901
1014 """Returns the PGFPlots code for an axis environment.
@@ -36,14 +40,14 @@ def __init__(self, data, obj): # noqa: C901
3640 title = obj .get_title ()
3741 data ["current axis title" ] = title
3842 if title :
39- title = mpl_backend_pgf . common_texification (title )
43+ title = _common_texification (title )
4044 self .axis_options .append (u"title={{{}}}" .format (title ))
4145
4246 # get axes titles
4347 xlabel = obj .get_xlabel ()
4448 xrotation = obj .xaxis .get_label ().get_rotation ()
4549 if xlabel :
46- xlabel = mpl_backend_pgf . common_texification (xlabel )
50+ xlabel = _common_texification (xlabel )
4751 self .axis_options .append (u"xlabel={{{}}}" .format (xlabel ))
4852 if xrotation != 0 :
4953 self .axis_options .append (
@@ -52,7 +56,7 @@ def __init__(self, data, obj): # noqa: C901
5256 ylabel = obj .get_ylabel ()
5357 yrotation = obj .yaxis .get_label ().get_rotation ()
5458 if ylabel :
55- ylabel = mpl_backend_pgf . common_texification (ylabel )
59+ ylabel = _common_texification (ylabel )
5660 self .axis_options .append (u"ylabel={{{}}}" .format (ylabel ))
5761 if yrotation != 90 :
5862 self .axis_options .append (
@@ -559,7 +563,7 @@ def _get_ticks(data, xy, ticks, ticklabels):
559563 # store the label anyway
560564 label = ticklabel .get_text ()
561565 if ticklabel .get_visible ():
562- label = mpl_backend_pgf . common_texification (label )
566+ label = _common_texification (label )
563567 pgfplots_ticklabels .append (label )
564568 else :
565569 is_label_required = True
0 commit comments