SourceForge logo
SourceForge logo
Menu

[matplotlib-devel] Patch suggestion

From: Nicholas Y. <su...@su...> - 2005年04月14日 15:39:41
Attachments: patch
Hi,
I'm a fairly heavy user of matplotlib (to plot results from plasma
physics simulations) and my use requires the display of fairly large
images.
Having done some testing I've discovered (after bypassing anything slow
from the python code) that for large images where there image size
approaches the available memory the main performance bar seems to be the
conversion of the raw data to the _image.Image class. The way in which
the conversion takes place - with data being taken non-sequentially from
many points in a floating point source array and then converted to an 1
byte integer - is slow and if swapping becomes involved even slower.
To overcome this problem I suggest implementing c++ code to allow the
creation of the image from a buffer (with each rgba pixel as 4 bytes)
rather than a floating point array. Where image data is being generated
elsewhere (in my case in Fortran code) it's trivial to output to a
different format and doing so means that the size of the input data can
be significantly smaller and that the data in the source array is
accessed sequentially (it's likely that a compiler will also be able to
optimise a copy of this data more effectively). The image can then be
scaled and over plotted as with any existing image.
I've attempted to implement this code myself (see attached patch to
src/_image.cpp) but I'm not a regular c++ or even c programmer so it's
fairly likely there will be memory leaks in the code. For a 1024x2048
array using the GTKAgg backend and with plenty of memory free this
change results in show() taking <0.7s rather than >4.6s; if there is a
memory shortage and swapping becomes involved the change is much more
noticeable. I haven't made any decent Python wrapping code yet - but
would be happy do do so if someone familiar with c++ could tidy up my
attachment.
Hope this is useful to others,
Nicholas Young

View entire thread

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /