From: <md...@us...> - 2007-11-14 19:46:39
|
Revision: 4292 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4292&view=rev Author: mdboom Date: 2007-11-14 11:46:37 -0800 (Wed, 14 Nov 2007) Log Message: ----------- Merged revisions 4244-4289 via svnmerge from http://matplotlib.svn.sf.net/svnroot/matplotlib/trunk/matplotlib ........ r4248 | dsdale | 2007-11-13 11:39:12 -0500 (Tue, 13 Nov 2007) | 2 lines modify formatting of comments in matplotlib.conf ........ r4249 | dsdale | 2007-11-13 13:10:32 -0500 (Tue, 13 Nov 2007) | 2 lines fixed some formatting issues in tconfig ........ r4264 | efiring | 2007-11-14 02:45:12 -0500 (Wed, 14 Nov 2007) | 2 lines A step towards a fast rectilinear pcolor version ........ r4267 | mdboom | 2007-11-14 08:58:08 -0500 (Wed, 14 Nov 2007) | 3 lines Fix bug when clicking "Cancel" in the save dialog in TkAgg backend. (Thanks Michael Zell). ........ r4268 | mdboom | 2007-11-14 09:00:56 -0500 (Wed, 14 Nov 2007) | 2 lines Fix bug in specgram. (Thanks Glen W. Mabey!) ........ r4275 | jdh2358 | 2007-11-14 11:39:47 -0500 (Wed, 14 Nov 2007) | 2 lines added glen's Fc specteal patch ........ r4278 | efiring | 2007-11-14 13:10:00 -0500 (Wed, 14 Nov 2007) | 2 lines Use mpl standard import idiom in image.py ........ r4287 | mdboom | 2007-11-14 14:06:52 -0500 (Wed, 14 Nov 2007) | 2 lines Fix placement of rotated text in Wx backend (thanks Michael Day). ........ r4288 | jdh2358 | 2007-11-14 14:11:54 -0500 (Wed, 14 Nov 2007) | 2 lines fixed is_string_like and removed is_file_like ........ r4289 | mdboom | 2007-11-14 14:25:46 -0500 (Wed, 14 Nov 2007) | 2 lines Refactored a bunch of places to use "is_writable_file_like". ........ Modified Paths: -------------- branches/transforms/API_CHANGES branches/transforms/lib/matplotlib/__init__.py branches/transforms/lib/matplotlib/axes.py branches/transforms/lib/matplotlib/backends/backend_agg.py branches/transforms/lib/matplotlib/backends/backend_gtk.py branches/transforms/lib/matplotlib/backends/backend_pdf.py branches/transforms/lib/matplotlib/backends/backend_ps.py branches/transforms/lib/matplotlib/backends/backend_svg.py branches/transforms/lib/matplotlib/backends/backend_tkagg.py branches/transforms/lib/matplotlib/backends/backend_wx.py branches/transforms/lib/matplotlib/cbook.py branches/transforms/lib/matplotlib/cm.py branches/transforms/lib/matplotlib/collections.py branches/transforms/lib/matplotlib/colorbar.py branches/transforms/lib/matplotlib/config/matplotlib.conf.default branches/transforms/lib/matplotlib/config/mplconfig.py branches/transforms/lib/matplotlib/config/mpltraits.py branches/transforms/lib/matplotlib/config/tconfig.py branches/transforms/lib/matplotlib/image.py branches/transforms/lib/matplotlib/lines.py branches/transforms/lib/matplotlib/mlab.py branches/transforms/lib/matplotlib/mpl-data/matplotlib.conf.template branches/transforms/lib/matplotlib/numerix/__init__.py branches/transforms/lib/matplotlib/pylab.py branches/transforms/setup.py branches/transforms/src/_image.cpp branches/transforms/src/_image.h Property Changed: ---------------- branches/transforms/ Property changes on: branches/transforms ___________________________________________________________________ Name: svnmerge-integrated - /trunk/matplotlib:1-4243 + /trunk/matplotlib:1-4289 Modified: branches/transforms/API_CHANGES =================================================================== --- branches/transforms/API_CHANGES 2007-11-14 19:45:49 UTC (rev 4291) +++ branches/transforms/API_CHANGES 2007-11-14 19:46:37 UTC (rev 4292) @@ -169,6 +169,9 @@ END OF TRANSFORMS REFACTORING + Changed cbook.is_file_like to cbook.is_writable_file_like and + corrected behavior. + Moved mlab.csv2rec -> recutils.csv2rec Added ax kwarg to pyplot.colorbar and Figure.colorbar so that Modified: branches/transforms/lib/matplotlib/__init__.py =================================================================== --- branches/transforms/lib/matplotlib/__init__.py 2007-11-14 19:45:49 UTC (rev 4291) +++ branches/transforms/lib/matplotlib/__init__.py 2007-11-14 19:46:37 UTC (rev 4292) @@ -118,8 +118,7 @@ def is_string_like(obj): - if hasattr(obj, 'shape'): return 0 # this is a workaround - # for a bug in numeric<23.1 + if hasattr(obj, 'shape'): return 0 try: obj + '' except (TypeError, ValueError): return 0 return 1 Modified: branches/transforms/lib/matplotlib/axes.py =================================================================== --- branches/transforms/lib/matplotlib/axes.py 2007-11-14 19:45:49 UTC (rev 4291) +++ branches/transforms/lib/matplotlib/axes.py 2007-11-14 19:46:37 UTC (rev 4292) @@ -4413,7 +4413,7 @@ origin=None, extent=None) IMSHOW(I) - plot image I to current axes, resampling to scale to axes - size (I may be numarray/Numeric array or PIL image) + size (I may be numpy array or PIL image) IMSHOW(I, X, Y) - plot image I to current axes, with nonuniform X and Y axes. (I, X and Y may be @@ -4988,10 +4988,10 @@ return n, bins, cbook.silent_list('Patch', patches) hist.__doc__ = cbook.dedent(hist.__doc__) % martist.kwdocd - def psd(self, x, NFFT=256, Fs=2, detrend=mlab.detrend_none, + def psd(self, x, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none, window=mlab.window_hanning, noverlap=0, **kwargs): """ - PSD(x, NFFT=256, Fs=2, detrend=mlab.detrend_none, + PSD(x, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none, window=mlab.window_hanning, noverlap=0, **kwargs) The power spectral density by Welches average periodogram method. The @@ -5002,22 +5002,27 @@ with a scaling to correct for power loss due to windowing. Fs is the sampling frequency. - NFFT is the length of the fft segment; must be a power of 2 + * NFFT is the length of the fft segment; must be a power of 2 - Fs is the sampling frequency. + * Fs is the sampling frequency. - detrend - the function applied to each segment before fft-ing, + * Fc is the center frequency of x (defaults to 0), which offsets + the yextents of the image to reflect the frequency range used + when a signal is acquired and then filtered and downsampled to + baseband. + + * detrend - the function applied to each segment before fft-ing, designed to remove the mean or linear trend. Unlike in matlab, where the detrend parameter is a vector, in matplotlib is it a function. The mlab module defines detrend_none, detrend_mean, detrend_linear, but you can use a custom function as well. - window - the function used to window the segments. window is a + * window - the function used to window the segments. window is a function, unlike in matlab(TM) where it is a vector. mlab defines window_none, window_hanning, but you can use a custom function as well. - noverlap gives the length of the overlap between segments. + * noverlap gives the length of the overlap between segments. Returns the tuple Pxx, freqs @@ -5035,6 +5040,7 @@ if not self._hold: self.cla() pxx, freqs = mlab.psd(x, NFFT, Fs, detrend, window, noverlap) pxx.shape = len(freqs), + freqs += Fc self.plot(freqs, 10*npy.log10(pxx), **kwargs) self.set_xlabel('Frequency') @@ -5052,10 +5058,10 @@ return pxx, freqs psd.__doc__ = cbook.dedent(psd.__doc__) % martist.kwdocd - def csd(self, x, y, NFFT=256, Fs=2, detrend=mlab.detrend_none, + def csd(self, x, y, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none, window=mlab.window_hanning, noverlap=0, **kwargs): """ - CSD(x, y, NFFT=256, Fs=2, detrend=mlab.detrend_none, + CSD(x, y, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none, window=window_hanning, noverlap=0, **kwargs) The cross spectral density Pxy by Welches average periodogram method. @@ -5081,6 +5087,7 @@ pxy, freqs = mlab.csd(x, y, NFFT, Fs, detrend, window, noverlap) pxy.shape = len(freqs), # pxy is complex + freqs += Fc self.plot(freqs, 10*npy.log10(npy.absolute(pxy)), **kwargs) self.set_xlabel('Frequency') @@ -5097,11 +5104,10 @@ return pxy, freqs csd.__doc__ = cbook.dedent(csd.__doc__) % martist.kwdocd - def cohere(self, x, y, NFFT=256, Fs=2, detrend=mlab.detrend_none, + def cohere(self, x, y, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none, window=mlab.window_hanning, noverlap=0, **kwargs): """ - COHERE(x, y, NFFT=256, Fs=2, - detrend = mlab.detrend_none, + COHERE(x, y, NFFT=256, Fs=2, Fc=0, detrend = mlab.detrend_none, window = mlab.window_hanning, noverlap=0, **kwargs) cohere the coherence between x and y. Coherence is the normalized @@ -5126,6 +5132,7 @@ """ if not self._hold: self.cla() cxy, freqs = mlab.cohere(x, y, NFFT, Fs, detrend, window, noverlap) + freqs += Fc self.plot(freqs, cxy, **kwargs) self.set_xlabel('Frequency') @@ -5135,11 +5142,11 @@ return cxy, freqs cohere.__doc__ = cbook.dedent(cohere.__doc__) % martist.kwdocd - def specgram(self, x, NFFT=256, Fs=2, detrend=mlab.detrend_none, + def specgram(self, x, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none, window=mlab.window_hanning, noverlap=128, cmap = None, xextent=None): """ - SPECGRAM(x, NFFT=256, Fs=2, detrend=mlab.detrend_none, + SPECGRAM(x, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none, window = mlab.window_hanning, noverlap=128, cmap=None, xextent=None) @@ -5181,7 +5188,8 @@ if xextent is None: xextent = 0, npy.amax(bins) xmin, xmax = xextent - extent = xmin, xmax, npy.amin(freqs), npy.amax(freqs) + freqs += Fc + extent = xmin, xmax, freqs[0], freqs[-1] im = self.imshow(Z, cmap, extent=extent) self.axis('auto') Modified: branches/transforms/lib/matplotlib/backends/backend_agg.py =================================================================== --- branches/transforms/lib/matplotlib/backends/backend_agg.py 2007-11-14 19:45:49 UTC (rev 4291) +++ branches/transforms/lib/matplotlib/backends/backend_agg.py 2007-11-14 19:46:37 UTC (rev 4292) @@ -19,8 +19,6 @@ * allow save to file handle * integrate screen dpi w/ ppi and text - -INSTALLING """ from __future__ import division import os, sys, weakref Modified: branches/transforms/lib/matplotlib/backends/backend_gtk.py =================================================================== --- branches/transforms/lib/matplotlib/backends/backend_gtk.py 2007-11-14 19:45:49 UTC (rev 4291) +++ branches/transforms/lib/matplotlib/backends/backend_gtk.py 2007-11-14 19:46:37 UTC (rev 4292) @@ -19,7 +19,7 @@ from matplotlib.backend_bases import RendererBase, GraphicsContextBase, \ FigureManagerBase, FigureCanvasBase, NavigationToolbar2, cursors from matplotlib.backends.backend_gdk import RendererGDK, FigureCanvasGDK -from matplotlib.cbook import is_string_like, enumerate +from matplotlib.cbook import is_string_like, is_writable_file_like, enumerate from matplotlib.colors import colorConverter from matplotlib.figure import Figure from matplotlib.widgets import SubplotTool @@ -370,7 +370,7 @@ pixbuf.save(filename, format) except gobject.GError, exc: error_msg_gtk('Save figure failure:\n%s' % (exc,), parent=self) - elif hasattr(filename, 'write') and callable(filename.write): + elif is_writable_file_like(filename): if hasattr(pixbuf, 'save_to_callback'): def save_callback(buf, data=None): data.write(buf) Modified: branches/transforms/lib/matplotlib/backends/backend_pdf.py =================================================================== --- branches/transforms/lib/matplotlib/backends/backend_pdf.py 2007-11-14 19:45:49 UTC (rev 4291) +++ branches/transforms/lib/matplotlib/backends/backend_pdf.py 2007-11-14 19:46:37 UTC (rev 4292) @@ -24,7 +24,8 @@ from matplotlib._pylab_helpers import Gcf from matplotlib.backend_bases import RendererBase, GraphicsContextBase,\ FigureManagerBase, FigureCanvasBase -from matplotlib.cbook import Bunch, enumerate, is_string_like, reverse_dict, get_realpath_and_stat +from matplotlib.cbook import Bunch, enumerate, is_string_like, reverse_dict, \ + get_realpath_and_stat, is_writable_file_like from matplotlib.figure import Figure from matplotlib.font_manager import findfont, is_opentype_cff_font from matplotlib.afm import AFM @@ -333,7 +334,7 @@ self.passed_in_file_object = False if is_string_like(filename): fh = file(filename, 'wb') - elif hasattr(filename, 'write') and callable(filename.write): + elif is_writable_file_like(filename): fh = filename self.passed_in_file_object = True else: Modified: branches/transforms/lib/matplotlib/backends/backend_ps.py =================================================================== --- branches/transforms/lib/matplotlib/backends/backend_ps.py 2007-11-14 19:45:49 UTC (rev 4291) +++ branches/transforms/lib/matplotlib/backends/backend_ps.py 2007-11-14 19:46:37 UTC (rev 4292) @@ -15,7 +15,8 @@ from matplotlib.backend_bases import RendererBase, GraphicsContextBase,\ FigureManagerBase, FigureCanvasBase -from matplotlib.cbook import is_string_like, izip, get_realpath_and_stat +from matplotlib.cbook import is_string_like, izip, get_realpath_and_stat, \ + is_writable_file_like from matplotlib.figure import Figure from matplotlib.font_manager import findfont, is_opentype_cff_font @@ -873,7 +874,7 @@ if is_string_like(outfile): title = outfile tmpfile = os.path.join(gettempdir(), md5.md5(outfile).hexdigest()) - elif hasattr(outfile, 'write') and callable(outfile.write): + elif is_writable_file_like(outfile): title = None tmpfile = os.path.join(gettempdir(), md5.md5(str(hash(outfile))).hexdigest()) passed_in_file_object = True Modified: branches/transforms/lib/matplotlib/backends/backend_svg.py =================================================================== --- branches/transforms/lib/matplotlib/backends/backend_svg.py 2007-11-14 19:45:49 UTC (rev 4291) +++ branches/transforms/lib/matplotlib/backends/backend_svg.py 2007-11-14 19:46:37 UTC (rev 4292) @@ -5,7 +5,7 @@ from matplotlib import verbose, __version__, rcParams from matplotlib.backend_bases import RendererBase, GraphicsContextBase,\ FigureManagerBase, FigureCanvasBase -from matplotlib.cbook import is_string_like +from matplotlib.cbook import is_string_like, is_writable_file_like from matplotlib.colors import rgb2hex from matplotlib.figure import Figure from matplotlib.font_manager import findfont, FontProperties @@ -503,7 +503,7 @@ def print_svg(self, filename, *args, **kwargs): if is_string_like(filename): fh_to_close = svgwriter = codecs.open(filename, 'w', 'utf-8') - elif hasattr(filename, 'write') and callable(filename.write): + elif is_writable_file_like(filename): svgwriter = codecs.EncodedFile(filename, 'utf-8') fh_to_close = None else: @@ -514,7 +514,7 @@ if is_string_like(filename): gzipwriter = gzip.GzipFile(filename, 'w') fh_to_close = svgwriter = codecs.EncodedFile(gzipwriter, 'utf-8') - elif hasattr(filename, 'write') and callable(filename.write): + elif is_writable_file_like(filename): fh_to_close = gzipwriter = gzip.GzipFile(fileobj=filename, mode='w') svgwriter = codecs.EncodedFile(gzipwriter, 'utf-8') else: Modified: branches/transforms/lib/matplotlib/backends/backend_tkagg.py =================================================================== --- branches/transforms/lib/matplotlib/backends/backend_tkagg.py 2007-11-14 19:45:49 UTC (rev 4291) +++ branches/transforms/lib/matplotlib/backends/backend_tkagg.py 2007-11-14 19:46:37 UTC (rev 4292) @@ -680,7 +680,7 @@ defaultextension = self.canvas.get_default_filetype() ) - if fname == "" : + if fname == "" or fname == (): return else: try: Modified: branches/transforms/lib/matplotlib/backends/backend_wx.py =================================================================== --- branches/transforms/lib/matplotlib/backends/backend_wx.py 2007-11-14 19:45:49 UTC (rev 4291) +++ branches/transforms/lib/matplotlib/backends/backend_wx.py 2007-11-14 19:46:37 UTC (rev 4292) @@ -152,7 +152,7 @@ cursors from matplotlib._pylab_helpers import Gcf from matplotlib.artist import Artist -from matplotlib.cbook import exception_to_str, is_string_like +from matplotlib.cbook import exception_to_str, is_string_like, is_writable_file_like from matplotlib.figure import Figure from matplotlib.path import Path from matplotlib.text import _process_text_args, Text @@ -343,8 +343,10 @@ if angle == 0.0: gfx_ctx.DrawText(s, x, y) else: - angle = angle * (math.pi / 180.0) - gfx_ctx.DrawRotatedText(s, x, y, angle) + angle = angle / 180.0 * math.pi + xo = h * math.sin(rads) + yo = h * math.cos(rads) + gfx_ctx.DrawRotatedText(s, x - xo, y - yo, angle) gc.unselect() @@ -976,7 +978,7 @@ # the error on a call or print_figure may not work because # printing can be qued and called from realize raise RuntimeError('Could not save figure to %s\n' % (filename)) - elif hasattr(filename, 'write') and callable(filename.write): + elif is_writable_file_like(filename): if not self.bitmap.ConvertToImage().SaveStream(filename, filetype): DEBUG_MSG('print_figure() file save error', 4, self) raise RuntimeError('Could not save figure to %s\n' % (filename)) Modified: branches/transforms/lib/matplotlib/cbook.py =================================================================== --- branches/transforms/lib/matplotlib/cbook.py 2007-11-14 19:45:49 UTC (rev 4291) +++ branches/transforms/lib/matplotlib/cbook.py 2007-11-14 19:46:37 UTC (rev 4292) @@ -209,20 +209,14 @@ def is_string_like(obj): - if hasattr(obj, 'shape'): return 0 # this is a workaround - # for a bug in numeric<23.1 + if hasattr(obj, 'shape'): return 0 try: obj + '' except (TypeError, ValueError): return 0 return 1 +def is_writable_file_like(obj): + return hasattr(filename, 'write') and callable(filename.write) -def is_file_like(obj): - if hasattr(obj, 'shape'): return 0 # this is a workaround - # for a bug in numeric<23.1 - try: obj + '' - except (TypeError, ValueError): return 0 - return 1 - def is_scalar(obj): return is_string_like(obj) or not iterable(obj) Modified: branches/transforms/lib/matplotlib/cm.py =================================================================== --- branches/transforms/lib/matplotlib/cm.py 2007-11-14 19:45:49 UTC (rev 4291) +++ branches/transforms/lib/matplotlib/cm.py 2007-11-14 19:46:37 UTC (rev 4292) @@ -56,7 +56,7 @@ return x def set_array(self, A): - 'Set the image array from numeric/numarray A' + 'Set the image array from numpy array A' self._A = A def get_array(self): Modified: branches/transforms/lib/matplotlib/collections.py =================================================================== --- branches/transforms/lib/matplotlib/collections.py 2007-11-14 19:45:49 UTC (rev 4291) +++ branches/transforms/lib/matplotlib/collections.py 2007-11-14 19:46:37 UTC (rev 4292) @@ -364,7 +364,7 @@ thus (meshWidth * meshHeight) quadrilaterals in the mesh. The mesh need not be regular and the polygons need not be convex. A quadrilateral mesh is represented by a - (2 x ((meshWidth + 1) * (meshHeight + 1))) Numeric array + (2 x ((meshWidth + 1) * (meshHeight + 1))) numpy array 'coordinates' where each row is the X and Y coordinates of one of the vertices. To define the function that maps from a data point to Modified: branches/transforms/lib/matplotlib/colorbar.py =================================================================== --- branches/transforms/lib/matplotlib/colorbar.py 2007-11-14 19:45:49 UTC (rev 4291) +++ branches/transforms/lib/matplotlib/colorbar.py 2007-11-14 19:46:37 UTC (rev 4292) @@ -508,7 +508,7 @@ N = len(b) ii = npy.minimum(npy.searchsorted(b, xn), N-1) i0 = npy.maximum(ii - 1, 0) - #db = b[ii] - b[i0] (does not work with Numeric) + #db = b[ii] - b[i0] db = npy.take(b, ii) - npy.take(b, i0) db = npy.where(i0==ii, 1.0, db) #dy = y[ii] - y[i0] Modified: branches/transforms/lib/matplotlib/config/matplotlib.conf.default =================================================================== --- branches/transforms/lib/matplotlib/config/matplotlib.conf.default 2007-11-14 19:45:49 UTC (rev 4291) +++ branches/transforms/lib/matplotlib/config/matplotlib.conf.default 2007-11-14 19:46:37 UTC (rev 4292) @@ -1,7 +1,7 @@ # MPLConfig - plaintext (in .conf format) # This is a sample matplotlib configuration file. It should be placed -# in HOME/.matplotlib/matplotlibrc (unix/linux like systems) and +# in HOME/.matplotlib (unix/linux like systems) and # C:\Documents and Settings\yourname\.matplotlib (win32 systems) # # By default, the installer will overwrite the existing file in the install Modified: branches/transforms/lib/matplotlib/config/mplconfig.py =================================================================== --- branches/transforms/lib/matplotlib/config/mplconfig.py 2007-11-14 19:45:49 UTC (rev 4291) +++ branches/transforms/lib/matplotlib/config/mplconfig.py 2007-11-14 19:46:37 UTC (rev 4292) @@ -23,7 +23,7 @@ class MPLConfig(TConfig): """ This is a sample matplotlib configuration file. It should be placed - in HOME/.matplotlib/matplotlibrc (unix/linux like systems) and + in HOME/.matplotlib (unix/linux like systems) and C:\Documents and Settings\yourname\.matplotlib (win32 systems) By default, the installer will overwrite the existing file in the install @@ -43,11 +43,11 @@ the default values listed herein. Colors: for the color values below, you can either use - - a matplotlib color string, such as r, k, or b + - a matplotlib color string, such as r | k | b - an rgb tuple, such as (1.0, 0.5, 0.0) - a hex string, such as #ff00ff or ff00ff - a scalar grayscale intensity such as 0.75 - - a legal html color name, eg red, blue, darkslategray + - a legal html color name, eg red | blue | darkslategray Interactivity: see http://matplotlib.sourceforge.net/interactive.html. @@ -63,8 +63,6 @@ units = T.false class backend(TConfig): - """Valid backends are: 'GTKAgg', 'GTKCairo', 'QtAgg', 'Qt4Agg', - 'TkAgg', 'Agg', 'Cairo', 'PS', 'PDF', 'SVG'""" use = T.Trait('Agg', mplT.BackendHandler()) class cairo(TConfig): Modified: branches/transforms/lib/matplotlib/config/mpltraits.py =================================================================== --- branches/transforms/lib/matplotlib/config/mpltraits.py 2007-11-14 19:45:49 UTC (rev 4291) +++ branches/transforms/lib/matplotlib/config/mpltraits.py 2007-11-14 19:46:37 UTC (rev 4292) @@ -24,18 +24,22 @@ class BackendHandler(T.TraitHandler): """ """ - backends = {'tkagg': 'TkAgg', + backends = {'agg': 'Agg', + 'cairo': 'Cairo', + 'cocoaagg': 'CocoaAgg', + 'fltkagg': 'FltkAgg', + 'gtk': 'GTK', 'gtkagg': 'GTKAgg', 'gtkcairo': 'GTKCairo', + 'pdf': 'Pdf', + 'ps': 'PS', 'qt4agg': 'Qt4Agg', 'qtagg': 'QtAgg', - 'wxagg': 'WXAgg', - 'agg': 'Agg', - 'cairo': 'Cairo', - 'ps': 'PS', - 'pdf': 'Pdf', 'svg': 'SVG', - 'template': 'Template' } + 'template': 'Template', + 'tkagg': 'TkAgg', + 'wx': 'WX', + 'wxagg': 'WXAgg'} def validate(self, object, name, value): try: @@ -46,7 +50,7 @@ def info(self): be = self.backends.keys() be.sort - return "one of %s"% ', '.join(['%s'%i for i in be]) + return "one of: %s"% ' | '.join(['%s'%i for i in be]) class BoolHandler(T.TraitHandler): @@ -73,7 +77,7 @@ return self.error(object, name, value) def info(self): - return "one of %s"% ', '.join(['%s'%i for i in self.bools.keys()]) + return "one of: %s"% ' | '.join(['%s'%i for i in self.bools.keys()]) flexible_true = T.Trait(True, BoolHandler()) flexible_false = T.Trait(False, BoolHandler()) Modified: branches/transforms/lib/matplotlib/config/tconfig.py =================================================================== --- branches/transforms/lib/matplotlib/config/tconfig.py 2007-11-14 19:45:49 UTC (rev 4291) +++ branches/transforms/lib/matplotlib/config/tconfig.py 2007-11-14 19:46:37 UTC (rev 4292) @@ -76,6 +76,50 @@ # Utility functions ############################################################################ +def get_split_ind(seq, N): + """seq is a list of words. Return the index into seq such that + len(' '.join(seq[:ind])<=N + """ + + sLen = 0 + # todo: use Alex's xrange pattern from the cbook for efficiency + for (word, ind) in zip(seq, range(len(seq))): + sLen += len(word) + 1 # +1 to account for the len(' ') + if sLen>=N: return ind + return len(seq) + +def wrap(prefix, text, cols, max_lines=6): + 'wrap text with prefix at length cols' + pad = ' '*len(prefix.expandtabs()) + available = cols - len(pad) + + seq = text.split(' ') + Nseq = len(seq) + ind = 0 + lines = [] + while ind<Nseq: + lastInd = ind + ind += get_split_ind(seq[ind:], available) + lines.append(seq[lastInd:ind]) + + num_lines = len(lines) + abbr_end = max_lines // 2 + abbr_start = max_lines - abbr_end + lines_skipped = False + for i in range(num_lines): + if i == 0: + # add the prefix to the first line, pad with spaces otherwise + ret = prefix + ' '.join(lines[i]) + '\n' + elif i < abbr_start or i > num_lines-abbr_end-1: + ret += pad + ' '.join(lines[i]) + '\n' + else: + if not lines_skipped: + lines_skipped = True + ret += ' <...snipped %d lines...> \n' % (num_lines-max_lines) +# for line in lines[1:]: +# ret += pad + ' '.join(line) + '\n' + return ret[:-1] + def dedent(txt): """A modified version of textwrap.dedent, specialized for docstrings. @@ -115,44 +159,6 @@ return ''.join(lines) -def short_str(txt,line_length=80,max_lines=6): - """Shorten a text input if necessary. - """ - - assert max_lines%2==0,"max_lines must be even" - - if txt.count('\n') <= 1: - # Break up auto-generated text that can be *very* long but in just one - # line. - ltxt = len(txt) - max_len = line_length*max_lines - chunk = max_lines/2 - - if ltxt > max_len: - out = [] - for n in range(chunk): - out.append(txt[line_length*n:line_length*(n+1)]) - - out.append(' <...snipped %d chars...> ' % (ltxt-max_len)) - - for n in range(-chunk-1,0,1): - # Special-casing for the last step of the loop, courtesy of - # Python's idiotic string slicign semantics when the second - # argument is 0. Argh. - end = line_length*(n+1) - if end==0: end = None - out.append(txt[line_length*n:end]) - - txt = '\n'.join(out) - else: - nlines = ltxt/line_length - out = [ txt[line_length*n:line_length*(n+1)] - for n in range(nlines+1)] - if out: - txt = '\n'.join(out) - return txt - - def configObj2Str(cobj): """Dump a Configobj instance to a string.""" outstr = StringIO() @@ -463,7 +469,7 @@ # Get a short version of info with lines of max. 78 chars, so # that after commenting them out (with '# ') they are at most # 80-chars long. - out.append(comment(short_str(info,78-len(indent)),indent)) + out.append(comment(wrap('',info.replace('\n', ' '),78-len(indent)),indent)) except (KeyError,AttributeError): pass out.append(indent+('%s = %r' % (s,v))) Modified: branches/transforms/lib/matplotlib/image.py =================================================================== --- branches/transforms/lib/matplotlib/image.py 2007-11-14 19:45:49 UTC (rev 4291) +++ branches/transforms/lib/matplotlib/image.py 2007-11-14 19:46:37 UTC (rev 4292) @@ -7,18 +7,23 @@ import os import numpy as npy -from matplotlib.numerix import npyma as ma +import matplotlib.numerix.npyma as ma + from matplotlib import rcParams -from artist import Artist -from colors import colorConverter -import cm -import _image +from matplotlib import artist as martist +from matplotlib import colors as mcolors +from matplotlib import cm +# For clarity, names from _image are given explicitly in this module: +from matplotlib import _image -from _image import * -class AxesImage(Artist, cm.ScalarMappable): +# For user convenience, the names from _image are also imported into +# the image namespace: +from matplotlib._image import * +class AxesImage(martist.Artist, cm.ScalarMappable): + def __init__(self, ax, cmap = None, norm = None, @@ -43,7 +48,7 @@ Additional kwargs are matplotlib.artist properties """ - Artist.__init__(self) + martist.Artist.__init__(self) cm.ScalarMappable.__init__(self, norm, cmap) if origin is None: origin = rcParams['image.origin'] @@ -99,7 +104,7 @@ ACCEPTS: float """ - Artist.set_alpha(self, alpha) + martist.Artist.set_alpha(self, alpha) self._imcache = None def changed(self): @@ -133,7 +138,8 @@ else: im = self._imcache - bg = colorConverter.to_rgba(self.axes.get_frame().get_facecolor(), 0) + fc = self.axes.get_frame().get_facecolor() + bg = mcolors.colorConverter.to_rgba(fc, 0) im.set_bg( *bg) # image input dimensions @@ -229,18 +235,18 @@ """ retained for backwards compatibility - use set_data instead - ACCEPTS: numeric/numarray/PIL Image A""" + ACCEPTS: numpy array A or PIL Image""" # This also needs to be here to override the inherited # cm.ScalarMappable.set_array method so it is not invoked # by mistake. self.set_data(A) - + def set_extent(self, extent): """extent is data axes (left, right, bottom, top) for making image plots """ self._extent = extent - + xmin, xmax, ymin, ymax = extent corners = (xmin, ymin), (xmax, ymax) self.axes.update_datalim(corners) @@ -330,10 +336,9 @@ height *= magnification im = _image.pcolor(self._Ax, self._Ay, self._A, height, width, - (x0, x0+v_width, y0, y0+v_height), - ) - - bg = colorConverter.to_rgba(self.axes.get_frame().get_facecolor(), 0) + (x0, x0+v_width, y0, y0+v_height)) + fc = self.axes.get_frame().get_facecolor() + bg = mcolors.colorConverter.to_rgba(fc, 0) im.set_bg(*bg) return im @@ -402,7 +407,7 @@ -class FigureImage(Artist, cm.ScalarMappable): +class FigureImage(martist.Artist, cm.ScalarMappable): def __init__(self, fig, cmap = None, norm = None, @@ -416,7 +421,7 @@ norm is a colors.Normalize instance to map luminance to 0-1 """ - Artist.__init__(self) + martist.Artist.__init__(self) cm.ScalarMappable.__init__(self, norm, cmap) if origin is None: origin = rcParams['image.origin'] self.origin = origin @@ -464,7 +469,8 @@ x = self.to_rgba(self._A, self._alpha) im = _image.fromarray(x, 1) - im.set_bg( *colorConverter.to_rgba(self.figure.get_facecolor(), 0) ) + fc = self.figure.get_facecolor() + im.set_bg( *mcolors.colorConverter.to_rgba(fc, 0) ) im.is_grayscale = (self.cmap.name == "gray" and len(self._A.shape) == 2) if self.origin=='upper': Modified: branches/transforms/lib/matplotlib/lines.py =================================================================== --- branches/transforms/lib/matplotlib/lines.py 2007-11-14 19:45:49 UTC (rev 4291) +++ branches/transforms/lib/matplotlib/lines.py 2007-11-14 19:46:37 UTC (rev 4292) @@ -229,7 +229,7 @@ """ Artist.__init__(self) - #convert sequences to numeric arrays + #convert sequences to numpy arrays if not iterable(xdata): raise RuntimeError('xdata must be a sequence') if not iterable(ydata): Modified: branches/transforms/lib/matplotlib/mlab.py =================================================================== --- branches/transforms/lib/matplotlib/mlab.py 2007-11-14 19:45:49 UTC (rev 4291) +++ branches/transforms/lib/matplotlib/mlab.py 2007-11-14 19:46:37 UTC (rev 4292) @@ -353,7 +353,7 @@ # zero pad x up to NFFT if it is shorter than NFFT if len(x)<NFFT: n = len(x) - x = resize(x, (NFFT,)) + x = npy.resize(x, (NFFT,)) x[n:] = 0 @@ -533,7 +533,7 @@ Cxy, Phase, freqs = cohere_pairs( X, ij, ...) Compute the coherence for all pairs in ij. X is a - numSamples,numCols Numeric array. ij is a list of tuples (i,j). + numSamples,numCols numpy array. ij is a list of tuples (i,j). Each tuple is a pair of indexes into the columns of X for which you want to compute coherence. For example, if X has 64 columns, and you want to compute all nonredundant pairs, define ij as @@ -894,7 +894,7 @@ Example 1 : ## 2D system - # Numeric solution + def derivs6(x,t): d1 = x[0] + 2*x[1] d2 = -3*x[0] + 4*x[1] @@ -1480,8 +1480,7 @@ """ A set of convenient utilities for numerical work. -Most of this module requires Numerical Python or is meant to be used with it. -See http://www.pfdubois.com/numpy for details. +Most of this module requires numpy or is meant to be used with it. Copyright (c) 2001-2004, Fernando Perez. <Fer...@co...> All rights reserved. @@ -1754,7 +1753,7 @@ #from numpy import fromfunction as fromfunction_kw def fromfunction_kw(function, dimensions, **kwargs): - """Drop-in replacement for fromfunction() from Numerical Python. + """Drop-in replacement for fromfunction() from numpy Allows passing keyword arguments to the desired function. @@ -1938,12 +1937,8 @@ ### end mlab2 functions -#Classes for manipulating and viewing numpy record arrays +#helpers for loading, saving, manipulating and viewing numpy record arrays - - - - def safe_isnan(x): 'isnan for arbitrary types' try: b = npy.isnan(x) @@ -2236,10 +2231,10 @@ # a series of classes for describing the format intentions of various rec views class FormatObj: def tostr(self, x): - return str(self.toval(x)) + return self.toval(x) def toval(self, x): - return x + return str(x) class FormatString(FormatObj): Modified: branches/transforms/lib/matplotlib/mpl-data/matplotlib.conf.template =================================================================== --- branches/transforms/lib/matplotlib/mpl-data/matplotlib.conf.template 2007-11-14 19:45:49 UTC (rev 4291) +++ branches/transforms/lib/matplotlib/mpl-data/matplotlib.conf.template 2007-11-14 19:46:37 UTC (rev 4292) @@ -21,11 +21,11 @@ # the default values listed herein. # # Colors: for the color values below, you can either use -# - a matplotlib color string, such as r, k, or b +# - a matplotlib color string, such as r | k | b # - an rgb tuple, such as (1.0, 0.5, 0.0) # - a hex string, such as #ff00ff or ff00ff # - a scalar grayscale intensity such as 0.75 -# - a legal html color name, eg red, blue, darkslategray +# - a legal html color name, eg red | blue | darkslategray # # Interactivity: see http://matplotlib.sourceforge.net/interactive.html. # @@ -33,20 +33,19 @@ # a value of type 'str' datapath = '/usr/lib64/python2.5/site-packages/matplotlib/mpl-data' -# one of 0, on, false, 1, no, n, y, off, yes, true +# one of: 0 | on | false | 1 | no | n | y | off | yes | true interactive = False # a value of type 'bool' maskedarray = False # 'numpy' or 'numeric' or 'numarray' numerix = 'numpy' -# 'Africa/Abidjan' or 'Africa/Accra' or 'Africa/Addis_Ababa' or 'Africa/Algiers' -# or 'Africa/Asmara' or 'Africa/Asmera' or 'Africa/Bamako' or 'Africa/Bangui' o -# r 'Africa/Banjul' or 'Africa/Bissau' or 'Africa/Blantyre' or 'Africa/Brazzavil -# <...snipped 10590 chars...> -# or 'Turkey' or 'UCT' or 'US/Alaska' or 'US/Aleutian' or 'US/Arizona' or 'US/Ce -# ntral' or 'US/East-Indiana' or 'US/Eastern' or 'US/Hawaii' or 'US/Indiana-Star -# ke' or 'US/Michigan' or 'US/Mountain' or 'US/Pacific' or 'US/Pacific-New' or ' -# US/Samoa' or 'UTC' or 'Universal' or 'W-SU' or 'WET' or 'Zulu' or 'posixrules' +# 'Africa/Abidjan' or 'Africa/Accra' or 'Africa/Addis_Ababa' or +# 'Africa/Algiers' or 'Africa/Asmara' or 'Africa/Asmera' or 'Africa/Bamako' or +# 'Africa/Bangui' or 'Africa/Banjul' or 'Africa/Bissau' or 'Africa/Blantyre' +# <...snipped 156 lines...> +# 'US/Michigan' or 'US/Mountain' or 'US/Pacific' or 'US/Pacific-New' or +# 'US/Samoa' or 'UTC' or 'Universal' or 'W-SU' or 'WET' or 'Zulu' or +# 'posixrules' timezone = 'UTC' # 'toolbar2' or None toolbar = 'toolbar2' @@ -64,23 +63,23 @@ # name like 'orange', a hex color like '#efefef', a grayscale intensity # like '0.5', or an RGBA tuple (1,0,0,1) facecolor = 'white' - # one of 0, on, false, 1, no, n, y, off, yes, true + # one of: 0 | on | false | 1 | no | n | y | off | yes | true grid = False - # one of 0, on, false, 1, no, n, y, off, yes, true + # one of: 0 | on | false | 1 | no | n | y | off | yes | true hold = True # any valid matplotlib color, eg an abbreviation like 'r' for red, a full # name like 'orange', a hex color like '#efefef', a grayscale intensity # like '0.5', or an RGBA tuple (1,0,0,1) labelcolor = 'black' - # a value of type 'float' or 'xx-small' or 'x-small' or 'small' or 'medium' - # or 'large' or 'x-large' or 'xx-large' + # a value of type 'float' or 'xx-small' or 'x-small' or 'small' or + # 'medium' or 'large' or 'x-large' or 'xx-large' labelsize = 'medium' # a value of type 'float' linewidth = 1.0 - # one of 0, on, false, 1, no, n, y, off, yes, true + # one of: 0 | on | false | 1 | no | n | y | off | yes | true polargrid = True - # a value of type 'float' or 'xx-small' or 'x-small' or 'small' or 'medium' - # or 'large' or 'x-large' or 'xx-large' + # a value of type 'float' or 'xx-small' or 'x-small' or 'small' or + # 'medium' or 'large' or 'x-large' or 'xx-large' titlesize = 'large' [[formatter]] @@ -88,10 +87,8 @@ limits = [-7.0, 7.0] [backend] - # Valid backends are: 'GTKAgg', 'GTKCairo', 'QtAgg', 'Qt4Agg', - # 'TkAgg', 'Agg', 'Cairo', 'PS', 'PDF', 'SVG' - # one of ps, qt4agg, tkagg, gtkagg, agg, cairo, gtkcairo, wxagg, qtagg, temp - # late, svg, pdf + # one of: ps | qt4agg | fltkagg | gtkagg | agg | cairo | gtk | gtkcairo | + # wxagg | tkagg | qtagg | template | svg | cocoaagg | pdf | wx use = 'Agg' [[cairo]] @@ -111,10 +108,10 @@ [[ps]] # 3 or 42 fonttype = 3 - # 'auto' or 'letter' or 'legal' or 'ledger' or 'A0' or 'A1' or 'A2' or ' - # A3' or 'A4' or 'A5' or 'A6' or 'A7' or 'A8' or 'A9' or 'A10' or 'B0' o - # r 'B1' or 'B2' or 'B3' or 'B4' or 'B5' or 'B6' or 'B7' or 'B8' or 'B9' - # or 'B10' + # 'auto' or 'letter' or 'legal' or 'ledger' or 'A0' or 'A1' or 'A2' or + # 'A3' or 'A4' or 'A5' or 'A6' or 'A7' or 'A8' or 'A9' or 'A10' or + # 'B0' or 'B1' or 'B2' or 'B3' or 'B4' or 'B5' or 'B6' or 'B7' or 'B8' + # or 'B9' or 'B10' papersize = 'letter' # a value of type 'bool' useafm = False @@ -191,16 +188,16 @@ serif = ['Bitstream Vera Serif', 'New Century Schoolbook', 'Century Schoolbook L', 'Utopia', 'ITC Bookman', 'Bookman', 'Nimbus Roman No9 L', 'Times New Roman', 'Times', 'Palatino', 'Charter', 'serif'] # a value of type 'float' size = 12.0 - # 'ultra-condensed' or 'extra-condensed' or 'condensed' or 'semi-condensed' - # or 'normal' or 'semi-expanded' or 'expanded' or 'extra-expanded' or 'ultra - # -expanded' or 'wider' or 'narrower' + # 'ultra-condensed' or 'extra-condensed' or 'condensed' or + # 'semi-condensed' or 'normal' or 'semi-expanded' or 'expanded' or + # 'extra-expanded' or 'ultra-expanded' or 'wider' or 'narrower' stretch = 'normal' # 'normal' or 'italic' or 'oblique' style = 'normal' # 'normal' or 'small-caps' variant = 'normal' - # 'normal' or 'bold' or 'bolder' or 'lighter' or 100 or 200 or 300 or 400 or - # 500 or 600 or 700 or 800 or 900 + # 'normal' or 'bold' or 'bolder' or 'lighter' or 100 or 200 or 300 or 400 + # or 500 or 600 or 700 or 800 or 900 weight = 'normal' [grid] @@ -216,18 +213,18 @@ [image] # a value of type 'float' or 'equal' or 'auto' aspect = 'equal' - # 'Accent' or 'Accent_r' or 'Blues' or 'Blues_r' or 'BrBG' or 'BrBG_r' or 'B - # uGn' or 'BuGn_r' or 'BuPu' or 'BuPu_r' or 'Dark2' or 'Dark2_r' or 'GnBu' o - # r 'GnBu_r' or 'Greens' or 'Greens_r' or 'Greys' or 'Greys_r' or 'OrRd' or - # <...snipped 1010 chars...> - # ist_stern' or 'gist_stern_r' or 'gist_yarg' or 'gist_yarg_r' or 'gray' or - # 'gray_r' or 'hot' or 'hot_r' or 'hsv' or 'hsv_r' or 'jet' or 'jet_r' or 'p - # ink' or 'pink_r' or 'prism' or 'prism_r' or 'spectral' or 'spectral_r' or - # 'spring' or 'spring_r' or 'summer' or 'summer_r' or 'winter' or 'winter_r' + # 'Accent' or 'Accent_r' or 'Blues' or 'Blues_r' or 'BrBG' or 'BrBG_r' or + # 'BuGn' or 'BuGn_r' or 'BuPu' or 'BuPu_r' or 'Dark2' or 'Dark2_r' or + # 'GnBu' or 'GnBu_r' or 'Greens' or 'Greens_r' or 'Greys' or 'Greys_r' or + # <...snipped 16 lines...> + # 'pink_r' or 'prism' or 'prism_r' or 'spectral' or 'spectral_r' or + # 'spring' or 'spring_r' or 'summer' or 'summer_r' or 'winter' or + # 'winter_r' cmap = 'jet' - # 'bilinear' or 'nearest' or 'bicubic' or 'spline16' or 'spline36' or 'hanni - # ng' or 'hamming' or 'hermite' or 'kaiser' or 'quadric' or 'catrom' or 'gau - # ssian' or 'bessel' or 'mitchell' or 'sinc' or 'lanczos' or 'blackman' + # 'bilinear' or 'nearest' or 'bicubic' or 'spline16' or 'spline36' or + # 'hanning' or 'hamming' or 'hermite' or 'kaiser' or 'quadric' or 'catrom' + # or 'gaussian' or 'bessel' or 'mitchell' or 'sinc' or 'lanczos' or + # 'blackman' interpolation = 'bilinear' # a value of type 'int' lut = 256 @@ -237,8 +234,8 @@ [legend] # a value of type 'float' axespad = 0.02 - # a value of type 'float' or 'xx-small' or 'x-small' or 'small' or 'medium' - # or 'large' or 'x-large' or 'xx-large' + # a value of type 'float' or 'xx-small' or 'x-small' or 'small' or + # 'medium' or 'large' or 'x-large' or 'xx-large' fontsize = 'medium' # a value of type 'float' handlelen = 0.050000000000000003 @@ -248,9 +245,9 @@ isaxes = True # a value of type 'float' labelsep = 0.01 - # 'best' or 'upper right' or 'upper left' or 'lower left' or 'lower right' o - # r 'right' or 'center left' or 'center right' or 'lower center' or 'upper c - # enter' or 'center' + # 'best' or 'upper right' or 'upper left' or 'lower left' or 'lower right' + # or 'right' or 'center left' or 'center right' or 'lower center' or + # 'upper center' or 'center' loc = 'upper right' # a value of type 'float' markerscale = 1.0 @@ -276,9 +273,9 @@ linestyle = '-' # a value of type 'float' linewidth = 1.0 - # 'None' or 'o' or '.' or ',' or '^' or 'v' or '<' or '>' or 's' or '+' or ' - # x' or 'D' or 'd' or '1' or '2' or '3' or '4' or 'h' or 'H' or 'p' or '|' o - # r '_' + # 'None' or 'o' or '.' or ',' or '^' or 'v' or '<' or '>' or 's' or '+' or + # 'x' or 'D' or 'd' or '1' or '2' or '3' or '4' or 'h' or 'H' or 'p' or + # '|' or '_' marker = 'None' # a value of type 'float' markeredgewidth = 0.5 @@ -290,27 +287,27 @@ solid_joinstyle = 'miter' [mathtext] - # A fontconfig pattern. See the fontconfig user manual for more information - # . + # A fontconfig pattern. See the fontconfig user manual for more + # information. bf = 'serif:bold' - # A fontconfig pattern. See the fontconfig user manual for more information - # . + # A fontconfig pattern. See the fontconfig user manual for more + # information. cal = 'cursive' # a value of type 'bool' fallback_to_cm = True # 'cm' or 'stix' or 'stixsans' or 'custom' fontset = 'cm' - # A fontconfig pattern. See the fontconfig user manual for more information - # . + # A fontconfig pattern. See the fontconfig user manual for more + # information. it = 'serif:oblique' - # A fontconfig pattern. See the fontconfig user manual for more information - # . + # A fontconfig pattern. See the fontconfig user manual for more + # information. rm = 'serif' - # A fontconfig pattern. See the fontconfig user manual for more information - # . + # A fontconfig pattern. See the fontconfig user manual for more + # information. sf = 'sans' - # A fontconfig pattern. See the fontconfig user manual for more information - # . + # A fontconfig pattern. See the fontconfig user manual for more + # information. tt = 'monospace' [patch] @@ -370,8 +367,8 @@ color = 'black' # 'in' or 'out' direction = 'in' - # a value of type 'float' or 'xx-small' or 'x-small' or 'small' or 'medium' - # or 'large' or 'x-large' or 'xx-large' + # a value of type 'float' or 'xx-small' or 'x-small' or 'small' or + # 'medium' or 'large' or 'x-large' or 'xx-large' labelsize = 'small' [[major]] @@ -393,8 +390,8 @@ color = 'black' # 'in' or 'out' direction = 'in' - # a value of type 'float' or 'xx-small' or 'x-small' or 'small' or 'medium' - # or 'large' or 'x-large' or 'xx-large' + # a value of type 'float' or 'xx-small' or 'x-small' or 'small' or + # 'medium' or 'large' or 'x-large' or 'xx-large' labelsize = 'small' [[major]] Modified: branches/transforms/lib/matplotlib/numerix/__init__.py =================================================================== --- branches/transforms/lib/matplotlib/numerix/__init__.py 2007-11-14 19:45:49 UTC (rev 4291) +++ branches/transforms/lib/matplotlib/numerix/__init__.py 2007-11-14 19:46:37 UTC (rev 4292) @@ -35,8 +35,10 @@ use_maskedarray = True if a == "--ma": use_maskedarray = False -del a +try: del a +except NameError: pass + if which[0] is None: try: # In theory, rcParams always has *some* value for numerix. which = rcParams['numerix'], "rc" Modified: branches/transforms/lib/matplotlib/pylab.py =================================================================== --- branches/transforms/lib/matplotlib/pylab.py 2007-11-14 19:45:49 UTC (rev 4291) +++ branches/transforms/lib/matplotlib/pylab.py 2007-11-14 19:46:37 UTC (rev 4292) @@ -191,11 +191,6 @@ __end -Credits: The plotting commands were provided by -John D. Hunter <jdh...@ac...> - -Most of the other commands are from Numeric, MLab and FFT, with the -exception of those in mlab.py provided by matplotlib. """ import sys, warnings Modified: branches/transforms/setup.py =================================================================== --- branches/transforms/setup.py 2007-11-14 19:45:49 UTC (rev 4291) +++ branches/transforms/setup.py 2007-11-14 19:46:37 UTC (rev 4292) @@ -169,7 +169,6 @@ if options['build_gtk']: if hasgtk or (options['build_gtk'] is True): build_gdk(ext_modules, packages) - rc['backend'] = 'GTK' if options['build_gtkagg']: if hasgtk or (options['build_gtkagg'] is True): options['build_agg'] = 1 @@ -264,15 +263,16 @@ distrib = setup(name="matplotlib", version= __version__, - description = "Matlab(TM) style python plotting package", + description = "Python plotting package", author = "John D. Hunter", author_email="jd...@gm...", url = "http://matplotlib.sourceforge.net", long_description = """ matplotlib strives to produce publication quality 2D graphics - using matlab plotting for inspiration. Although the main lib is - object oriented, there is a functional interface "pylab" - for people coming from Matlab. + for interactive graphing, scientific publishing, user interface + development and web application servers targeting multiple user + interfaces and hardcopy output formats. There is a 'pylab' mode + which emulates matlab graphics """, packages = packages, platforms='any', Modified: branches/transforms/src/_image.cpp =================================================================== --- branches/transforms/src/_image.cpp 2007-11-14 19:45:49 UTC (rev 4291) +++ branches/transforms/src/_image.cpp 2007-11-14 19:46:37 UTC (rev 4292) @@ -1403,8 +1403,8 @@ // Create output Image* imo = new Image; imo->rowsIn = rows; + imo->colsIn = cols; imo->rowsOut = rows; - imo->colsIn = cols; imo->colsOut = cols; size_t NUMBYTES(rows * cols * 4); agg::int8u *buffer = new agg::int8u[NUMBYTES]; @@ -1499,6 +1499,227 @@ return Py::asObject(imo); } +void _bin_indices(int *irows, int nrows, double *y, int ny, + double sc, double offs) +{ + int i; + if (sc*(y[ny-1] - y[0]) > 0) + { + int ii = 0; + int iilast = ny-1; + int iy0 = (int)floor(sc * (y[ii] - offs)); + int iy1 = (int)floor(sc * (y[ii+1] - offs)); + for (i=0; i<nrows && i<iy0; i++) { + irows[i] = -1; + } + for (; i<nrows; i++) { + while (i > iy1 && ii < iilast) { + ii++; + iy0 = iy1; + iy1 = (int)floor(sc * (y[ii+1] - offs)); + } + if (i >= iy0 && i <= iy1) irows[i] = ii; + else break; + } + for (; i<nrows; i++) { + irows[i] = -1; + } + } + else + { + int iilast = ny-1; + int ii = iilast; + int iy0 = (int)floor(sc * (y[ii] - offs)); + int iy1 = (int)floor(sc * (y[ii-1] - offs)); + for (i=0; i<nrows && i<iy0; i++) { + irows[i] = -1; + } + for (; i<nrows; i++) { + while (i > iy1 && ii > 1) { + ii--; + iy0 = iy1; + iy1 = (int)floor(sc * (y[ii-1] - offs)); + } + if (i >= iy0 && i <= iy1) irows[i] = ii-1; + else break; + } + for (; i<nrows; i++) { + irows[i] = -1; + } + } +} + +char __image_module_pcolor2__doc__[] = +"pcolor2(x, y, data, rows, cols, bounds, bg)\n" +"\n" +"Generate a pseudo-color image from data on a non-uniform grid\n" +"specified by its cell boundaries.\n" +"bounds = (x_left, x_right, y_bot, y_top)\n" +"bg = ndarray of 4 uint8 representing background rgba\n" +; +Py::Object +_image_module::pcolor2(const Py::Tuple& args) { + _VERBOSE("_image_module::pcolor2"); + + if (args.length() != 7) + throw Py::TypeError("Incorrect number of arguments (6 expected)"); + + Py::Object xp = args[0]; + Py::Object yp = args[1]; + Py::Object dp = args[2]; + int rows = Py::Int(args[3]); + int cols = Py::Int(args[4]); + Py::Tuple bounds = args[5]; + Py::Object bgp = args[6]; + + if (bounds.length() !=4) + throw Py::TypeError("Incorrect number of bounds (4 expected)"); + double x_left = Py::Float(bounds[0]); + double x_right = Py::Float(bounds[1]); + double y_bot = Py::Float(bounds[2]); + double y_top = Py::Float(bounds[3]); + + // Check we have something to output to + if (rows == 0 || cols ==0) + throw Py::ValueError("rows or cols is zero; there are no pixels"); + + // Get numpy arrays + PyArrayObject *x = (PyArrayObject *) PyArray_ContiguousFromObject(xp.ptr(), + PyArray_DOUBLE, 1, 1); + if (x == NULL) + throw Py::ValueError("x is of incorrect type (wanted 1D double)"); + PyArrayObject *y = (PyArrayObject *) PyArray_ContiguousFromObject(yp.ptr(), + PyArray_DOUBLE, 1, 1); + if (y == NULL) { + Py_XDECREF(x); + throw Py::ValueError("y is of incorrect type (wanted 1D double)"); + } + PyArrayObject *d = (PyArrayObject *) PyArray_ContiguousFromObject(dp.ptr(), + PyArray_UBYTE, 3, 3); + if (d == NULL) { + Py_XDECREF(x); + Py_XDECREF(y); + throw Py::ValueError("data is of incorrect type (wanted 3D uint8)"); + } + if (d->dimensions[2] != 4) { + Py_XDECREF(x); + Py_XDECREF(y); + Py_XDECREF(d); + throw Py::ValueError("data must be in RGBA format"); + } + + // Check dimensions match + int nx = x->dimensions[0]; + int ny = y->dimensions[0]; + if (nx != d->dimensions[1]+1 || ny != d->dimensions[0]+1) { + Py_XDECREF(x); + Py_XDECREF(y); + Py_XDECREF(d); + throw Py::ValueError("data and axis bin boundary dimensions are incompatible"); + } + + PyArrayObject *bg = (PyArrayObject *) PyArray_ContiguousFromObject(bgp.ptr(), + PyArray_UBYTE, 1, 1); + if (bg == NULL) { + Py_XDECREF(x); + Py_XDECREF(y); + Py_XDECREF(d); + throw Py::ValueError("bg is of incorrect type (wanted 1D uint8)"); + } + if (bg->dimensions[0] != 4) { + Py_XDECREF(x); + Py_XDECREF(y); + Py_XDECREF(d); + Py_XDECREF(bg); + throw Py::ValueError("bg must be in RGBA format"); + } + + + // Allocate memory for pointer arrays + int * irows = reinterpret_cast<int*>(PyMem_Malloc(sizeof(int)*rows)); + if (irows == NULL) { + Py_XDECREF(x); + Py_XDECREF(y); + Py_XDECREF(d); + Py_XDECREF(bg); + throw Py::MemoryError("Cannot allocate memory for lookup table"); + } + int * jcols = reinterpret_cast<int*>(PyMem_Malloc(sizeof(int*)*cols)); + if (jcols == NULL) { + Py_XDECREF(x); + Py_XDECREF(y); + Py_XDECREF(d); + Py_XDECREF(bg); + PyMem_Free(irows); + throw Py::MemoryError("Cannot allocate memory for lookup table"); + } + + // Create output + Image* imo = new Image; + imo->rowsIn = rows; + imo->rowsOut = rows; + imo->colsIn = cols; + imo->colsOut = cols; + size_t NUMBYTES(rows * cols * 4); + agg::int8u *buffer = new agg::int8u[NUMBYTES]; + if (buffer == NULL) { + Py_XDECREF(x); + Py_XDECREF(y); + Py_XDECREF(d); + Py_XDECREF(bg); + PyMem_Free(irows); + PyMem_Free(jcols); + throw Py::MemoryError("Could not allocate memory for image"); + } + + // Calculate the pointer arrays to map input x to output x + int i, j; + double *x0 = reinterpret_cast<double*>(x->data); + double *y0 = reinterpret_cast<double*>(y->data); + double sx = cols/(x_right - x_left); + double sy = rows/(y_top - y_bot); + _bin_indices(jcols, cols, x0, nx, sx, x_left); + _bin_indices(irows, rows, y0, ny, sy, y_bot); + + // Copy data to output buffer + agg::int8u * position = buffer; + unsigned char *start = reinterpret_cast<unsigned char*>(d->data); + unsigned char *bgptr = reinterpret_cast<unsigned char*>(bg->data); + int s0 = d->strides[0]; + int s1 = d->strides[1]; + + for (i=0; i<rows; i++) + { + for (j=0; j<cols; j++) + { + if (irows[i] == -1 || jcols[j] == -1) { + memcpy(position, bgptr, 4*sizeof(agg::int8u)); + } + else { + memcpy(position, (start + s0*irows[i] + s1*jcols[j]), + 4*sizeof(agg::int8u)); + } + position += 4; + } + } + + // Attach output buffer to output buffer + imo->rbufOut = new agg::rendering_buffer; + imo->bufferOut = buffer; + imo->rbufOut->attach(imo->bufferOut, imo->colsOut, imo->rowsOut, imo->colsOut * imo->BPP); + + Py_XDECREF(x); + Py_XDECREF(y); + Py_XDECREF(d); + Py_XDECREF(bg); + PyMem_Free(irows); + PyMem_Free(jcols); + + return Py::asObject(imo); +} + + + #if defined(_MSC_VER) DL_EXPORT(void) #elif defined(__cplusplus) @@ -1532,7 +1753,7 @@ d["SINC"] = Py::Int(Image::SINC); d["LANCZOS"] = Py::Int(Image::LANCZOS); d["BLACKMAN"] = Py::Int(Image::BLACKMAN); - + d["ASPECT_FREE"] = Py::Int(Image::ASPECT_FREE); d["ASPECT_PRESERVE"] = Py::Int(Image::ASPECT_PRESERVE); Modified: branches/transforms/src/_image.h =================================================================== --- branches/transforms/src/_image.h 2007-11-14 19:45:49 UTC (rev 4291) +++ branches/transforms/src/_image.h 2007-11-14 19:46:37 UTC (rev 4292) @@ -134,6 +134,8 @@ "from_images"); add_varargs_method("pcolor", &_image_module::pcolor, "pcolor"); + add_varargs_method("pcolor2", &_image_module::pcolor2, + "pcolor2"); initialize( "The _image module" ); } @@ -145,11 +147,13 @@ Py::Object fromarray (const Py::Tuple &args); Py::Object fromarray2 (const Py::Tuple &args); Py::Object pcolor (const Py::Tuple &args); + Py::Object pcolor2 (const Py::Tuple &args); Py::Object readpng (const Py::Tuple &args); Py::Object from_images (const Py::Tuple &args); static char _image_module_fromarray__doc__[]; static char _image_module_pcolor__doc__[]; + static char _image_module_pcolor2__doc__[]; static char _image_module_fromarray2__doc__[]; static char _image_module_frombyte__doc__[]; static char _image_module_frombuffer__doc__[]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |