From: <as...@us...> - 2009-02-10 04:43:27
|
Revision: 6899 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6899&view=rev Author: astraw Date: 2009-02-10 04:43:23 +0000 (Tue, 10 Feb 2009) Log Message: ----------- Add imsave() to matplotlib.image, pyplot, and pylab. Patch from Gary Ruben. Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/doc/_templates/index.html trunk/matplotlib/doc/api/api_changes.rst trunk/matplotlib/lib/matplotlib/image.py trunk/matplotlib/lib/matplotlib/pylab.py trunk/matplotlib/lib/matplotlib/pyplot.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2009-02-09 23:05:22 UTC (rev 6898) +++ trunk/matplotlib/CHANGELOG 2009-02-10 04:43:23 UTC (rev 6899) @@ -1,3 +1,6 @@ +2009-02-08 Added a new imsave function to image.py and exposed it in + the pyplot interface - GR + 2009-02-04 Some reorgnization of the legend code. anchored_text.py added as an example. - JJL Modified: trunk/matplotlib/doc/_templates/index.html =================================================================== --- trunk/matplotlib/doc/_templates/index.html 2009-02-09 23:05:22 UTC (rev 6898) +++ trunk/matplotlib/doc/_templates/index.html 2009-02-10 04:43:23 UTC (rev 6899) @@ -567,6 +567,17 @@ </tr> <tr> <th align="left"> + <a href="api/pyplot_api.html#matplotlib.pyplot.imsave">imsave</a> + + </th> + + <td align="left"> + save array as an image file + </td> + + </tr> + <tr> + <th align="left"> <a href="api/pyplot_api.html#matplotlib.pyplot.imshow">imshow</a> </th> Modified: trunk/matplotlib/doc/api/api_changes.rst =================================================================== --- trunk/matplotlib/doc/api/api_changes.rst 2009-02-09 23:05:22 UTC (rev 6898) +++ trunk/matplotlib/doc/api/api_changes.rst 2009-02-10 04:43:23 UTC (rev 6899) @@ -19,6 +19,9 @@ Changes for 0.98.x ================== +* Added new :func:`matplotlib.image.imsave` and exposed it to the + :mod:`matplotlib.pyplot` interface. + * Remove support for pyExcelerator in exceltools -- use xlwt instead Modified: trunk/matplotlib/lib/matplotlib/image.py =================================================================== --- trunk/matplotlib/lib/matplotlib/image.py 2009-02-09 23:05:22 UTC (rev 6898) +++ trunk/matplotlib/lib/matplotlib/image.py 2009-02-10 04:43:23 UTC (rev 6899) @@ -747,7 +747,43 @@ return handler(fname) +def imsave(fname, arr, vmin=None, vmax=None, cmap=None, format=None, origin=None): + """ + Saves a 2D :class:`numpy.array` as an image with one pixel per element. + The output formats available depend on the backend being used. + Arguments: + *fname*: + A string containing a path to a filename, or a Python file-like object. + If *format* is *None* and *fname* is a string, the output + format is deduced from the extension of the filename. + *arr*: + A 2D array. + Keyword arguments: + *vmin*/*vmax*: [ None | scalar ] + *vmin* and *vmax* set the color scaling for the image by fixing the + values that map to the colormap color limits. If either *vmin* or *vmax* + is None, that limit is determined from the *arr* min/max value. + *cmap*: + cmap is a colors.Colormap instance, eg cm.jet. + If None, default to the rc image.cmap value. + *format*: + One of the file extensions supported by the active + backend. Most backends support png, pdf, ps, eps and svg. + *origin* + [ 'upper' | 'lower' ] Indicates where the [0,0] index of + the array is in the upper left or lower left corner of + the axes. Defaults to the rc image.origin value. + """ + from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas + from matplotlib.figure import Figure + + fig = Figure(figsize=arr.shape[::-1], dpi=1, frameon=False) + canvas = FigureCanvas(fig) + fig.figimage(arr, cmap=cmap, vmin=vmin, vmax=vmax, origin=origin) + fig.savefig(fname, dpi=1, format=format) + + def pil_to_array( pilImage ): """ load a PIL image and return it as a numpy array of uint8. For Modified: trunk/matplotlib/lib/matplotlib/pylab.py =================================================================== --- trunk/matplotlib/lib/matplotlib/pylab.py 2009-02-09 23:05:22 UTC (rev 6898) +++ trunk/matplotlib/lib/matplotlib/pylab.py 2009-02-10 04:43:23 UTC (rev 6899) @@ -50,6 +50,7 @@ ion - turn interaction mode on isinteractive - return True if interaction mode is on imread - load image file into array + imsave - save array as an image file imshow - plot image data ishold - return the hold state of the current axes legend - make an axes legend Modified: trunk/matplotlib/lib/matplotlib/pyplot.py =================================================================== --- trunk/matplotlib/lib/matplotlib/pyplot.py 2009-02-09 23:05:22 UTC (rev 6898) +++ trunk/matplotlib/lib/matplotlib/pyplot.py 2009-02-10 04:43:23 UTC (rev 6899) @@ -6,6 +6,7 @@ from matplotlib.figure import Figure, figaspect from matplotlib.backend_bases import FigureCanvasBase from matplotlib.image import imread as _imread +from matplotlib.image import imsave as _imsave from matplotlib import rcParams, rcParamsDefault, get_backend from matplotlib.rcsetup import interactive_bk as _interactive_bk from matplotlib.artist import getp, get, Artist @@ -1181,6 +1182,7 @@ legend add a legend to the axes loglog a log log plot imread load image file into array + imsave save array as an image file imshow plot image data matshow display a matrix in a new figure preserving aspect pcolor make a pseudocolor plot @@ -1230,7 +1232,7 @@ def get_plot_commands(): return ( 'axes', 'axis', 'bar', 'boxplot', 'cla', 'clf', 'close', 'colorbar', 'cohere', 'csd', 'draw', 'errorbar', 'figlegend', 'figtext', 'figimage', 'figure', 'fill', 'gca', - 'gcf', 'gci', 'get', 'gray', 'barh', 'jet', 'hist', 'hold', 'imread', + 'gcf', 'gci', 'get', 'gray', 'barh', 'jet', 'hist', 'hold', 'imread', 'imsave', 'imshow', 'legend', 'loglog', 'quiver', 'rc', 'pcolor', 'pcolormesh', 'plot', 'psd', 'savefig', 'scatter', 'set', 'semilogx', 'semilogy', 'show', 'specgram', 'stem', 'subplot', 'table', 'text', 'title', 'xlabel', @@ -1370,6 +1372,11 @@ if _imread.__doc__ is not None: imread.__doc__ = dedent(_imread.__doc__) +def imsave(*args, **kwargs): + return _imsave(*args, **kwargs) +if _imsave.__doc__ is not None: + imsave.__doc__ = dedent(_imsave.__doc__) + def matshow(A, fignum=None, **kw): """ Display an array as a matrix in a new figure window. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |