title: matplotlib with pgf, error: dimension too large
body: <p>In using the <code>pgf</code> backend of <code>matplotlib</code>, I sometimes see an error like this:</p>
  <pre><code>! Dimension too large.
  &lt;to be read again&gt; 
                     \advance 
  l.69 ...o{\pgfqpoint{-11.400000in}{-235.382893in}}
  </code></pre>
  <p>This is from the LaTeX processing step, it will happen if I ask matplotlib for a png, or when processing a document with the pgf file embedded. It happens when I set axes limits that are very narrow compared to the data limits. So I assume that pgf receives and tries to process or plot the whole data set, and some of the points that are outside the intended visible range are also outside pgf's internal size limit.</p>
  <p>MWE:</p>
  <pre><code>import matplotlib as mpl
  mpl.use(&quot;pgf&quot;)
  import numpy as np
  import matplotlib.pyplot as plt
  
  x = np.linspace(-5,5)
  y = 100*np.exp(x)
  
  plt.xlim((-0.1,0.1))
  plt.ylim((99,101))
  
  plt.plot(x,y)
  plt.savefig('exp.png')
  </code></pre>
  <p>My question: <strong>is there some way that I can have matplotlib feed pgf a limited set of data?</strong> Or is there some other solution to this? I could truncate the data I feed into the pyplot command according to my desired limits, but I'm hoping matplotlib has an internal solution to save me from a lot of case-by-case fidgeting. (There's also a case when I'm adding spline patches to the axes, I don't know how to cut off part of the curve.)</p>
  <p>I've looked in some of the documentation and saw <code>get_clip_on()</code> and <code>get_clip_box()</code> of <code>Line2D</code>, but after any regular plot command the former method returns True anyway and the latter returns some <code>TransformedBbox</code> specification, presumably something representing the axes themselves.</p>