[matplotlib-devel] PATCH: Accept color/alpha in imsave

2012-04-07 Thread Jostein Bø Fløystad
I've had problems saving MxNx3 (RGB) numpy arrays as images using
imsave. It fails with an exception, and the problem seems to be line
1243 in image.py:

figsize = [x / float(dpi) for x in arr.shape[::-1]]

The purpose of arr.shape[::-1] seems to be to reorder the height and
width dimensions. It works as intended for MxN arrays, but not NxMx3
arrays -- they cause a function to complain about an argument too
many.

I have modified the above line to use (arr.shape[1], arr.shape[0])
instead of arr.shape[::-1], and that solves the problem for me, and I
get the output I expect (and the code still passes all tests it should
pass). However, there could very well be subtleties in the codebase
that I don't know about.

The attached patches add a simple test case, the above mentioned
change and a few updates to the documentation of imsave.

Best,

Jostein.


0001-Add-test-for-color-alpha-handling-in-imsave.patch
Description: Binary data


0002-Fix-imsave-to-accept-a-third-color-alpha-dimension.patch
Description: Binary data
--
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


Re: [matplotlib-devel] Saving animations

2012-04-07 Thread Benjamin Root
On Sat, Apr 7, 2012 at 1:34 PM, Tony Yu  wrote:

> I've been using the animations subpackage since it was introduced, but I
> only recently tried to save an animation using the `save` method.
> Unfortnately, I get a RuntimeError whenever I try to use it:
>
> ...
>   File
> "/Users/Tony/python/devel/mpl/lib/matplotlib/backends/backend_agg.py", line
> 4
> 52, in print_raw
> renderer._renderer.write_rgba(filename_or_obj)
> RuntimeError: Error writing to file
>
>
> This can be reproduced with any animation example, e.g. 
> simple_anim.py,
>  by
> replacing `plt.show()` with `ani.save('simple_anim.avi')`. The actual error
> is from a shell call to ffmpeg, which roughly boils down to:
>
> #
> import subprocess
> import matplotlib.pyplot as plt
>
> fig, ax = plt.subplots()
> ax.plot([0, 1])
> command = ['ffmpeg', '-f', 'rawvideo', '-vcodec', 'rawvideo',
>'-s', '800x600', '-pix_fmt', 'rgba', '-r', '5.0',
>'-i', 'pipe:', '-vcodec', 'mpeg4', '-y', 'test.avi']
> proc= subprocess.Popen(command, shell=False, stdout=subprocess.PIPE,
>stderr=subprocess.STDOUT, stdin=subprocess.PIPE)
> fileobj = proc.stdin
> fig.savefig(fileobj, format='rgba', dpi=100)
> #
>
> (I just copied the ffmpeg command from an example run, so the option
> values may vary on other systems.) The error here is the same, and,
> unfortunately, not very informative. Is this saving functionality platform
> dependent? (I'm on osx.)
>
> Thanks,
> -Tony
>
>
Tony,

The animation saving feature has be completely rewritten by Ryan recently
and is in master.  Could you give that a try?

Ben Root
--
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel