In using the pgf
backend of matplotlib
, I sometimes see an error like this:
! Dimension too large.
<to be read again>
\advance
l.69 ...o{\pgfqpoint{-11.400000in}{-235.382893in}}
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.
MWE:
import matplotlib as mpl
mpl.use("pgf")
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')
My question: is there some way that I can have matplotlib feed pgf a limited set of data? 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.)
I've looked in some of the documentation and saw get_clip_on()
and get_clip_box()
of Line2D
, but after any regular plot command the former method returns True anyway and the latter returns some TransformedBbox
specification, presumably something representing the axes themselves.