title: matplotlib PGF output: Contour labels extend beyond figure boundary
body: <p>Taking the first example from the <a href="https://matplotlib.org/examples/pylab_examples/contour_demo.html" rel="nofollow noreferrer"><code>matplotlib</code> examples page</a>,</p>
  
  <pre><code>import matplotlib
  import numpy as np
  import matplotlib.cm as cm
  import matplotlib.mlab as mlab
  import matplotlib.pyplot as plt
  
  matplotlib.rcParams['xtick.direction'] = 'out'
  matplotlib.rcParams['ytick.direction'] = 'out'
  
  delta = 0.025
  x = np.arange(-3.0, 3.0, delta)
  y = np.arange(-2.0, 2.0, delta)
  X, Y = np.meshgrid(x, y)
  Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
  Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
  # difference of Gaussians
  Z = 10.0 * (Z2 - Z1)
  
  
  # Create a simple contour plot with labels using default colors.  The
  # inline argument to clabel will control whether the labels are draw
  # over the line segments of the contour, removing the lines beneath
  # the label
  plt.figure()
  CS = plt.contour(X, Y, Z)
  plt.clabel(CS, inline=1, fontsize=10)
  plt.title('Simplest default with labels')
  
  plt.savefig('plot.pgf')
  </code></pre>
  
  <p>I have the problem that contour labels close to the axes (here, “0.000” at the very top) jut out beyond the figure boundary. Here is the output I get using LaTeX:
  <a href="https://i.stack.imgur.com/4Lz2N.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4Lz2N.png" alt="Contour plot produced with PGF/LaTeX"></a>
  As you can see, the label “0.000” at the top overlaps the black line.</p>
  
  <p>Is there anything I can do to fix this? To be clear, my issue is <em>not</em> that the label is close to the axis. What I want is the same behavior as shown on the <a href="https://matplotlib.org/examples/pylab_examples/contour_demo.html" rel="nofollow noreferrer"><code>matplotlib</code> page</a>, namely that the plot content is clipped to the figure area, cutting off text as well as lines.</p>