-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
too large file size created by the errorbar of matplotlib #3345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
what does |
I use matplotlib v1.3.1. |
Could you please give some numbers for reference? I would suggest testing the Cairo backend as a work around: import matplotlib
matplotlib.use('cairo')
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(0)
x = np.linspace(-5., 5., 5000)
y = 3 * np.exp(-0.5 * (x - 1.3)**2 / 0.8**2)
y += np.random.normal(0., 0.2, x.shape)
f = plt.figure(0)
plt.errorbar(x,y, yerr=0.2,fmt='')
f.savefig('test.pdf') These are the results that I get from testing your plot (MPL 1.4.x branch). I don't have access to IDL so I have no clue about the sizes that it generates.
Another thing is that the errorbars in this plot makes no sense IMHO since they are all on top of each other. I would reduce the number of errorbars with the |
The original backend is MacOSX, the file size is about 1.5 MB. If I create an eps file and then use ps2pdf, the pdf file size is about 232 KB. |
I have tried use cairo backend with OSX 10.9, but I got an error |
How large is the IDL file? You probably don't have the right dependencies for the cairo backend. You will need either cairocffi or pycairo installed and working but without some more details about how you installed matplotlib and python it is impossible to know. The cairo backend certainly works on OS X 10.9 |
@jkseppan I have a hunch that is related to a bug that was reported to me verbally, but hasn't made it into the tracker yet. When saving collections the pdf backend creates a new nested group (not sure if that is the correct pdf term) for every element instead of putting all of the elements in a single group. I also suspect that this is related to the some what funny way we use graphic contexts. |
IDL can not create PDF file directly. It can create an eps file, and then I use ps2pdf to get a PDF file about 180 KB. |
I use Anaconda, the matplotlib is included in Anaconda. |
Thanks It does't look like conda packs pycairo or cairocffi so that will not work right away. |
It seems that the errorbars get rendered using separate XObjects instead of just outputting the moveto and lineto operations in the page, and that blows up the file size. |
@jkseppan: That makes sense. Markers (which include ticks) all use XObjects, which normally results in a reduction in file size when those markers are used frequently. But maybe ticks are simple enough that not using XObjects is actually better. |
See #3485 for a proposed fix. |
There could be a deeper problem somewhere. Why is draw_path_collection being called with collections of one path each? It seems that there is code in Collection.draw that is intended to call draw_markers for such collections. |
The cost calculations are very rough, back-of-the-envelope. In the example from matplotlib#3345 I get significant file size reductions: 2.3M before.svg 1.8M after.svg 916K before.ps 672K after.ps
I was tring to plot a lot of data with errors using errobar of matplotlib. The eps or pdf file is very large, much larger than created by IDL. I have tried to use rasterized=True, but it does not work. If I only use plt.plot(x,y) to plot the data without errors, it can create a much smaller file. I am using OSX 10.9 and Anaconda. Here is the example of my code
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(0)
x = np.linspace(-5., 5., 5000)
y = 3 * np.exp(-0.5 * (x - 1.3)2 / 0.82)
y += np.random.normal(0., 0.2, x.shape)
f = plt.figure(0)
plt.errorbar(x,y, yerr=0.2,fmt='')
f.savefig('test.pdf')
The text was updated successfully, but these errors were encountered: