title: Matplotlib - Setting a tick label's background colour
body: <p>I have a subplot and its tick labels overlap with the data. <strong>I would like to set the x-tick labels to have a background colour</strong> (e.g. white). Currently I have only been able to find how to change the label's colour, but not the background. I know how to get the effect using a text object as shown below. (NB - I don't want the whole subplot's margin to be coloured, but just the tick label).</p>
  <h1>MWE</h1>
  <p><a href="https://i.stack.imgur.com/AgvhG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AgvhG.png" alt="enter image description here" /></a></p>
  <pre><code>import matplotlib as mpl
  
  rc_fonts = {
      &quot;text.usetex&quot;: True,
      'text.latex.preview': True,
      &quot;font.size&quot;: 50,
      'mathtext.default': 'regular',
      'axes.titlesize': 55,
      &quot;axes.labelsize&quot;: 55,
      &quot;legend.fontsize&quot;: 50,
      &quot;xtick.labelsize&quot;: 50,
      &quot;ytick.labelsize&quot;: 50,
      'figure.titlesize': 55,
      'figure.figsize': (10, 6.5),  # 15, 9.3
      'text.latex.preamble': [
          r&quot;&quot;&quot;\usepackage{lmodern,amsmath,amssymb,bm,physics,mathtools,nicefrac,letltxmacro,fixcmex}
          &quot;&quot;&quot;],
      &quot;font.family&quot;: &quot;serif&quot;,
      &quot;font.serif&quot;: &quot;computer modern roman&quot;,
  }
  mpl.rcParams.update(rc_fonts)
  import matplotlib.pylab as plt
  from mpl_toolkits.axes_grid1.inset_locator import inset_axes, InsetPosition, mark_inset
  from numpy import linspace, sin
  
  
  x = linspace(0, 1, 100)
  plt.clf()
  ax1 = plt.gca()
  ax2 = plt.axes([0, 0, 1, 1], label=str(2))
  ip = InsetPosition(ax1, [0.08, 0.63, 0.45, 0.3])
  ax2.set_axes_locator(ip)
  ax1.plot(x, x)
  ax1.plot(x, x + 0.3)
  ax1.set_xlim(0, 1)
  ax1.set_ylim(0, 1)
  ax2.xaxis.set_tick_params(labelcolor='r')
  ax1.text(0.3, 0.3, '$1$', transform=ax1.transAxes, horizontalalignment='center', verticalalignment='center', color='black', backgroundcolor='white')
  </code></pre>