Matplotlib with pgf, error: size is too large

When using the matplotlib pgf backend, sometimes I see this error:

! Dimension too large. <to be read again> \advance l.69 ...o{\pgfqpoint{-11.400000in}{-235.382893in}} 

This is a LaTeX processing step, this will happen if I ask matplotlib for png or process a document with an embedded pgf file. This happens when I set axle limits that are very narrow compared to data limits. Therefore, I assume that pgf receives and tries to process or build the entire dataset, and some of the points that are outside the intended visible range are also outside the internal size of pgf.

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: is there a way I can have matplotlib feed pgf a limited dataset? Or is there some other solution for this? I could truncate the data I submit to the pyplot command according to my desired limits, but I hope matplotlib has an internal solution to save me from a lot of random fiding. (There's also the case when I add spline patches to the axes, I don't know how to cut off part of the curve.)

I looked through some of the documentation and saw get_clip_on() and get_clip_box() of Line2D , but after any regular plot command, the previous method returns True anyway, and the latter returns some TransformedBbox specification, presumably something representing the axes themselves.

+6
source share

Source: https://habr.com/ru/post/982228/


All Articles