I've got some code where I'm using MPL (not pyplot) via imshow() to show some arrays and then am using savefig() to save them as PNG files.
The arrays are approx 3,000 x 4,000 in size.
My problem is that saving is taking a long time - on the order of 4 seconds or so per image.
Minor Details
- The arrays are floats
- I'm using cmap of gray
- I'm making sure the figure resolution is the same as the images, and the axes fills the entire figure (so fig size * dpi matches exactly the shape of the arrays)
- I'm using
imshow()with interpolation ofnone. - Running on macbook pro - but running on anything else is about the same (assuming SSD)
The slowness seems to be due to CPU bottleneck. Using time wrapped around my code shows real and user time to be about the same, so it doesn't seem to be a IO bottleneck.
However, (very curiously!), if I run the code via Multiprocessing in multiple processes, it doesn't seem to help much with overall real time (even with 4 cores).
Questions
- Is saving to PNG taking around 4 seconds 'normal'?
- Any tips or ideas on how to speed things up?