From: <md...@us...> - 2010-05-03 18:37:45
|
Revision: 8292 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8292&view=rev Author: mdboom Date: 2010-05-03 18:37:38 +0000 (Mon, 03 May 2010) Log Message: ----------- Change "import numpy as npy" to common convention "import numpy as np" Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/backends/backend_agg.py trunk/matplotlib/lib/matplotlib/backends/backend_cairo.py trunk/matplotlib/lib/matplotlib/backends/backend_gdk.py trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py trunk/matplotlib/lib/matplotlib/backends/backend_ps.py trunk/matplotlib/lib/matplotlib/backends/backend_wx.py trunk/matplotlib/lib/matplotlib/mathtext.py trunk/matplotlib/lib/matplotlib/projections/polar.py Modified: trunk/matplotlib/lib/matplotlib/backends/backend_agg.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_agg.py 2010-04-30 16:54:10 UTC (rev 8291) +++ trunk/matplotlib/lib/matplotlib/backends/backend_agg.py 2010-05-03 18:37:38 UTC (rev 8292) @@ -22,7 +22,7 @@ """ from __future__ import division -import numpy as npy +import numpy as np from matplotlib import verbose, rcParams from matplotlib.backend_bases import RendererBase,\ @@ -99,10 +99,10 @@ npts = path.vertices.shape[0] if (nmax > 100 and npts > nmax and path.should_simplify and rgbFace is None and gc.get_hatch() is None): - nch = npy.ceil(npts/float(nmax)) - chsize = int(npy.ceil(npts/nch)) - i0 = npy.arange(0, npts, chsize) - i1 = npy.zeros_like(i0) + nch = np.ceil(npts/float(nmax)) + chsize = int(np.ceil(npts/nch)) + i0 = np.arange(0, npts, chsize) + i1 = np.zeros_like(i0) i1[:-1] = i0[1:] - 1 i1[-1] = npts for ii0, ii1 in zip(i0, i1): @@ -196,7 +196,7 @@ im = self.texd.get(key) if im is None: Z = texmanager.get_grey(s, size, self.dpi) - Z = npy.array(Z * 255.0, npy.uint8) + Z = np.array(Z * 255.0, np.uint8) self._renderer.draw_text_image(Z, x, y, angle, gc) @@ -339,7 +339,7 @@ self._update_methods() if w > 0 and h > 0: - img = npy.fromstring(buffer, npy.uint8) + img = np.fromstring(buffer, np.uint8) img, ox, oy = post_processing(img.reshape((h, w, 4)) / 255., self.dpi) image = fromarray(img, 1) Modified: trunk/matplotlib/lib/matplotlib/backends/backend_cairo.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_cairo.py 2010-04-30 16:54:10 UTC (rev 8291) +++ trunk/matplotlib/lib/matplotlib/backends/backend_cairo.py 2010-05-03 18:37:38 UTC (rev 8292) @@ -21,7 +21,7 @@ from __future__ import division import os, sys, warnings, gzip -import numpy as npy +import numpy as np def _fn_name(): return sys._getframe(1).f_code.co_name @@ -196,7 +196,7 @@ ctx.save() if angle: - ctx.rotate (-angle * npy.pi / 180) + ctx.rotate (-angle * np.pi / 180) ctx.set_font_size (size) ctx.show_text (s.encode("utf-8")) ctx.restore() @@ -211,7 +211,7 @@ ctx.save() ctx.translate(x, y) if angle: - ctx.rotate (-angle * npy.pi / 180) + ctx.rotate (-angle * np.pi / 180) for font, fontsize, s, ox, oy in glyphs: ctx.new_path() @@ -355,7 +355,7 @@ self.ctx.set_dash([], 0) # switch dashes off else: self.ctx.set_dash ( - self.renderer.points_to_pixels (npy.asarray(dashes)), offset) + self.renderer.points_to_pixels (np.asarray(dashes)), offset) def set_foreground(self, fg, isRGB=None): @@ -469,7 +469,7 @@ ctx = renderer.gc.ctx if orientation == 'landscape': - ctx.rotate (npy.pi/2) + ctx.rotate (np.pi/2) ctx.translate (0, -height_in_points) # cairo/src/cairo_ps_surface.c # '%%Orientation: Portrait' is always written to the file header Modified: trunk/matplotlib/lib/matplotlib/backends/backend_gdk.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_gdk.py 2010-04-30 16:54:10 UTC (rev 8291) +++ trunk/matplotlib/lib/matplotlib/backends/backend_gdk.py 2010-05-03 18:37:38 UTC (rev 8292) @@ -16,7 +16,7 @@ % (gtk.pygtk_version + pygtk_version_required)) del pygtk_version_required -import numpy as npy +import numpy as np import matplotlib from matplotlib._pylab_helpers import Gcf @@ -109,7 +109,7 @@ im.flipud_out() rows, cols, image_str = im.as_rgba_str() - image_array = npy.fromstring(image_str, npy.uint8) + image_array = np.fromstring(image_str, np.uint8) image_array.shape = rows, cols, 4 pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, @@ -174,13 +174,13 @@ N = imw * imh # a numpixels by num fonts array - Xall = npy.zeros((N,1), npy.uint8) + Xall = np.zeros((N,1), np.uint8) image_str = font_image.as_str() - Xall[:,0] = npy.fromstring(image_str, npy.uint8) + Xall[:,0] = np.fromstring(image_str, np.uint8) # get the max alpha at each pixel - Xs = npy.amax(Xall,axis=1) + Xs = np.amax(Xall,axis=1) # convert it to it's proper shape Xs.shape = imh, imw @@ -381,7 +381,7 @@ if dash_list == None: self.gdkGC.line_style = gdk.LINE_SOLID else: - pixels = self.renderer.points_to_pixels(npy.asarray(dash_list)) + pixels = self.renderer.points_to_pixels(np.asarray(dash_list)) dl = [max(1, int(round(val))) for val in pixels] self.gdkGC.set_dashes(dash_offset, dl) self.gdkGC.line_style = gdk.LINE_ON_OFF_DASH Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py 2010-04-30 16:54:10 UTC (rev 8291) +++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py 2010-05-03 18:37:38 UTC (rev 8292) @@ -13,7 +13,7 @@ import warnings import zlib -import numpy as npy +import numpy as np from cStringIO import StringIO from datetime import datetime @@ -136,7 +136,7 @@ # need to use %f with some precision. Perhaps the precision # should adapt to the magnitude of the number? elif isinstance(obj, float): - if not npy.isfinite(obj): + if not np.isfinite(obj): raise ValueError, "Can only output finite numbers in PDF" r = "%.10f" % obj return r.rstrip('0').rstrip('.') @@ -1088,8 +1088,8 @@ shape = points.shape flat_points = points.reshape((shape[0] * shape[1], 2)) flat_colors = colors.reshape((shape[0] * shape[1], 4)) - points_min = npy.min(flat_points, axis=0) - (1 << 8) - points_max = npy.max(flat_points, axis=0) + (1 << 8) + points_min = np.min(flat_points, axis=0) - (1 << 8) + points_max = np.max(flat_points, axis=0) + (1 << 8) factor = float(0xffffffff) / (points_max - points_min) self.beginStream( @@ -1105,7 +1105,7 @@ 0, 1, 0, 1, 0, 1] }) - streamarr = npy.empty( + streamarr = np.empty( (shape[0] * shape[1],), dtype=[('flags', 'u1'), ('points', '>u4', (2,)), @@ -1137,7 +1137,7 @@ def _rgb(self, im): h,w,s = im.as_rgba_str() - rgba = npy.fromstring(s, npy.uint8) + rgba = np.fromstring(s, np.uint8) rgba.shape = (h, w, 4) rgb = rgba[:,:,:3] a = rgba[:,:,3:] @@ -1145,13 +1145,13 @@ def _gray(self, im, rc=0.3, gc=0.59, bc=0.11): rgbat = im.as_rgba_str() - rgba = npy.fromstring(rgbat[2], npy.uint8) + rgba = np.fromstring(rgbat[2], np.uint8) rgba.shape = (rgbat[0], rgbat[1], 4) - rgba_f = rgba.astype(npy.float32) + rgba_f = rgba.astype(np.float32) r = rgba_f[:,:,0] g = rgba_f[:,:,1] b = rgba_f[:,:,2] - gray = (r*rc + g*gc + b*bc).astype(npy.uint8) + gray = (r*rc + g*gc + b*bc).astype(np.uint8) return rgbat[0], rgbat[1], gray.tostring() def writeImages(self): @@ -2005,9 +2005,9 @@ try: different = bool(ours != theirs) except ValueError: - ours = npy.asarray(ours) - theirs = npy.asarray(theirs) - different = ours.shape != theirs.shape or npy.any(ours != theirs) + ours = np.asarray(ours) + theirs = np.asarray(theirs) + different = ours.shape != theirs.shape or np.any(ours != theirs) if different: break Modified: trunk/matplotlib/lib/matplotlib/backends/backend_ps.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2010-04-30 16:54:10 UTC (rev 8291) +++ trunk/matplotlib/lib/matplotlib/backends/backend_ps.py 2010-05-03 18:37:38 UTC (rev 8292) @@ -36,7 +36,7 @@ from matplotlib.backends.backend_mixed import MixedModeRenderer -import numpy as npy +import numpy as np import binascii import re try: @@ -127,7 +127,7 @@ #ok, neither are None:, assuming iterable if len(seq1) != len(seq2): return False - return npy.alltrue(npy.equal(seq1, seq2)) + return np.alltrue(np.equal(seq1, seq2)) class RendererPS(RendererBase): @@ -348,20 +348,20 @@ def _rgb(self, im): h,w,s = im.as_rgba_str() - rgba = npy.fromstring(s, npy.uint8) + rgba = np.fromstring(s, np.uint8) rgba.shape = (h, w, 4) rgb = rgba[:,:,:3] return h, w, rgb.tostring() def _gray(self, im, rc=0.3, gc=0.59, bc=0.11): rgbat = im.as_rgba_str() - rgba = npy.fromstring(rgbat[2], npy.uint8) + rgba = np.fromstring(rgbat[2], np.uint8) rgba.shape = (rgbat[0], rgbat[1], 4) - rgba_f = rgba.astype(npy.float32) + rgba_f = rgba.astype(np.float32) r = rgba_f[:,:,0] g = rgba_f[:,:,1] b = rgba_f[:,:,2] - gray = (r*rc + g*gc + b*bc).astype(npy.uint8) + gray = (r*rc + g*gc + b*bc).astype(np.uint8) return rgbat[0], rgbat[1], gray.tostring() def _hex_lines(self, s, chars_per_line=128): @@ -811,14 +811,14 @@ shape = points.shape flat_points = points.reshape((shape[0] * shape[1], 2)) flat_colors = colors.reshape((shape[0] * shape[1], 4)) - points_min = npy.min(flat_points, axis=0) - (1 << 8) - points_max = npy.max(flat_points, axis=0) + (1 << 8) + points_min = np.min(flat_points, axis=0) - (1 << 8) + points_max = np.max(flat_points, axis=0) + (1 << 8) factor = float(0xffffffff) / (points_max - points_min) xmin, ymin = points_min xmax, ymax = points_max - streamarr = npy.empty( + streamarr = np.empty( (shape[0] * shape[1],), dtype=[('flags', 'u1'), ('points', '>u4', (2,)), @@ -1492,7 +1492,7 @@ return a postscript header stringfor the given bbox (l, b, r, t) """ - bbox_info = '%%%%BoundingBox: %d %d %d %d' % (l, b, npy.ceil(r), npy.ceil(t)) + bbox_info = '%%%%BoundingBox: %d %d %d %d' % (l, b, np.ceil(r), np.ceil(t)) hires_bbox_info = '%%%%HiResBoundingBox: %.6f %.6f %.6f %.6f' % (l, b, r, t) return '\n'.join([bbox_info, hires_bbox_info]) @@ -1537,7 +1537,7 @@ dy = (bbox[3]-bbox[1])/2 l,b,r,t = (x-dx, y-dy, x+dx, y+dy) - bbox_info = '%%%%BoundingBox: %d %d %d %d' % (l, b, npy.ceil(r), npy.ceil(t)) + bbox_info = '%%%%BoundingBox: %d %d %d %d' % (l, b, np.ceil(r), np.ceil(t)) hires_bbox_info = '%%%%HiResBoundingBox: %.6f %.6f %.6f %.6f' % (l, b, r, t) return '\n'.join([bbox_info, hires_bbox_info]) Modified: trunk/matplotlib/lib/matplotlib/backends/backend_wx.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_wx.py 2010-04-30 16:54:10 UTC (rev 8291) +++ trunk/matplotlib/lib/matplotlib/backends/backend_wx.py 2010-05-03 18:37:38 UTC (rev 8292) @@ -96,7 +96,7 @@ import sys, os, os.path, math, StringIO, weakref, warnings -import numpy as npy +import numpy as np # Debugging settings here... # Debug level set here. If the debug level is less than 5, information @@ -417,7 +417,7 @@ w=self.width h=self.height rows, cols, image_str = im.as_rgba_str() - image_array = npy.fromstring(image_str, npy.uint8) + image_array = np.fromstring(image_str, np.uint8) image_array.shape = rows, cols, 4 bitmap = wx.BitmapFromBufferRGBA(cols,rows,image_array) gc = self.get_gc() Modified: trunk/matplotlib/lib/matplotlib/mathtext.py =================================================================== --- trunk/matplotlib/lib/matplotlib/mathtext.py 2010-04-30 16:54:10 UTC (rev 8291) +++ trunk/matplotlib/lib/matplotlib/mathtext.py 2010-05-03 18:37:38 UTC (rev 8292) @@ -3033,7 +3033,6 @@ Returns the offset of the baseline from the bottom of the image in pixels. """ - rgba, depth = self.to_rgba(texstr, color=color, dpi=dpi, fontsize=fontsize) numrows, numcols, tmp = rgba.shape _png.write_png(rgba.tostring(), numcols, numrows, filename) Modified: trunk/matplotlib/lib/matplotlib/projections/polar.py =================================================================== --- trunk/matplotlib/lib/matplotlib/projections/polar.py 2010-04-30 16:54:10 UTC (rev 8291) +++ trunk/matplotlib/lib/matplotlib/projections/polar.py 2010-05-03 18:37:38 UTC (rev 8292) @@ -1,7 +1,7 @@ import math import warnings -import numpy as npy +import numpy as np import matplotlib rcParams = matplotlib.rcParams @@ -36,13 +36,13 @@ is_separable = False def transform(self, tr): - xy = npy.zeros(tr.shape, npy.float_) + xy = np.zeros(tr.shape, np.float_) t = tr[:, 0:1] r = tr[:, 1:2] x = xy[:, 0:1] y = xy[:, 1:2] - x[:] = r * npy.cos(t) - y[:] = r * npy.sin(t) + x[:] = r * np.cos(t) + y[:] = r * np.sin(t) return xy transform.__doc__ = Transform.transform.__doc__ @@ -106,10 +106,10 @@ def transform(self, xy): x = xy[:, 0:1] y = xy[:, 1:] - r = npy.sqrt(x*x + y*y) - theta = npy.arccos(x / r) - theta = npy.where(y < 0, 2 * npy.pi - theta, theta) - return npy.concatenate((theta, r), 1) + r = np.sqrt(x*x + y*y) + theta = np.arccos(x / r) + theta = np.where(y < 0, 2 * np.pi - theta, theta) + return np.concatenate((theta, r), 1) transform.__doc__ = Transform.transform.__doc__ def inverted(self): @@ -125,14 +125,14 @@ def __call__(self, x, pos=None): # \u00b0 : degree symbol if rcParams['text.usetex'] and not rcParams['text.latex.unicode']: - return r"$%0.0f^\circ$" % ((x / npy.pi) * 180.0) + return r"$%0.0f^\circ$" % ((x / np.pi) * 180.0) else: # we use unicode, rather than mathtext with \circ, so # that it will work correctly with any arbitrary font # (assuming it has a degree sign), whereas $5\circ$ # will only work correctly with one of the supported # math fonts (Computer Modern and STIX) - return u"%0.0f\u00b0" % ((x / npy.pi) * 180.0) + return u"%0.0f\u00b0" % ((x / np.pi) * 180.0) class RadialLocator(Locator): """ @@ -196,7 +196,7 @@ self.title.set_y(1.05) self.xaxis.set_major_formatter(self.ThetaFormatter()) - angles = npy.arange(0.0, 360.0, 45.0) + angles = np.arange(0.0, 360.0, 45.0) self.set_thetagrids(angles) self.yaxis.set_major_locator(self.RadialLocator(self.yaxis.get_major_locator())) @@ -254,7 +254,7 @@ # axis so the gridlines from 0.0 to 1.0, now go from 0.0 to # 2pi. self._yaxis_transform = ( - Affine2D().scale(npy.pi * 2.0, 1.0) + + Affine2D().scale(np.pi * 2.0, 1.0) + self.transData) # The r-axis labels are put at an angle and padded in the r-direction self._r_label1_position = Affine2D().translate(22.5, self._rpad) @@ -344,8 +344,8 @@ ACCEPTS: sequence of floats """ - angles = npy.asarray(angles, npy.float_) - self.set_xticks(angles * (npy.pi / 180.0)) + angles = np.asarray(angles, np.float_) + self.set_xticks(angles * (np.pi / 180.0)) if labels is not None: self.set_xticklabels(labels) elif fmt is not None: @@ -384,7 +384,7 @@ ACCEPTS: sequence of floats """ - radii = npy.asarray(radii) + radii = np.asarray(radii) rmin = radii.min() if rmin <= 0: raise ValueError('radial grids must be strictly positive') @@ -411,7 +411,7 @@ def set_xlim(self, *args, **kargs): # The xlim is fixed, no matter what you do - self.viewLim.intervalx = (0.0, npy.pi * 2.0) + self.viewLim.intervalx = (0.0, np.pi * 2.0) def format_coord(self, theta, r): """ @@ -440,10 +440,10 @@ return False def start_pan(self, x, y, button): - angle = self._r_label1_position.to_values()[4] / 180.0 * npy.pi + angle = self._r_label1_position.to_values()[4] / 180.0 * np.pi mode = '' if button == 1: - epsilon = npy.pi / 45.0 + epsilon = np.pi / 45.0 t, r = self.transData.inverted().transform_point((x, y)) if t >= angle - epsilon and t <= angle + epsilon: mode = 'drag_r_labels' @@ -477,7 +477,7 @@ dt = abs(dt1) * sign(dt0) * -1.0 else: dt = dt0 * -1.0 - dt = (dt / npy.pi) * 180.0 + dt = (dt / np.pi) * 180.0 rpad = self._r_label1_position.to_values()[5] self._r_label1_position.clear().translate( @@ -499,26 +499,26 @@ # cubic bezier curves. # def transform_path(self, path): -# twopi = 2.0 * npy.pi -# halfpi = 0.5 * npy.pi +# twopi = 2.0 * np.pi +# halfpi = 0.5 * np.pi # vertices = path.vertices # t0 = vertices[0:-1, 0] # t1 = vertices[1: , 0] -# td = npy.where(t1 > t0, t1 - t0, twopi - (t0 - t1)) +# td = np.where(t1 > t0, t1 - t0, twopi - (t0 - t1)) # maxtd = td.max() -# interpolate = npy.ceil(maxtd / halfpi) +# interpolate = np.ceil(maxtd / halfpi) # if interpolate > 1.0: # vertices = self.interpolate(vertices, interpolate) # vertices = self.transform(vertices) -# result = npy.zeros((len(vertices) * 3 - 2, 2), npy.float_) -# codes = mpath.Path.CURVE4 * npy.ones((len(vertices) * 3 - 2, ), mpath.Path.code_type) +# result = np.zeros((len(vertices) * 3 - 2, 2), np.float_) +# codes = mpath.Path.CURVE4 * np.ones((len(vertices) * 3 - 2, ), mpath.Path.code_type) # result[0] = vertices[0] # codes[0] = mpath.Path.MOVETO -# kappa = 4.0 * ((npy.sqrt(2.0) - 1.0) / 3.0) +# kappa = 4.0 * ((np.sqrt(2.0) - 1.0) / 3.0) # kappa = 0.5 # p0 = vertices[0:-1] @@ -556,36 +556,36 @@ # return mpath.Path(result, codes) -# twopi = 2.0 * npy.pi -# halfpi = 0.5 * npy.pi +# twopi = 2.0 * np.pi +# halfpi = 0.5 * np.pi # vertices = path.vertices # t0 = vertices[0:-1, 0] # t1 = vertices[1: , 0] -# td = npy.where(t1 > t0, t1 - t0, twopi - (t0 - t1)) +# td = np.where(t1 > t0, t1 - t0, twopi - (t0 - t1)) # maxtd = td.max() -# interpolate = npy.ceil(maxtd / halfpi) +# interpolate = np.ceil(maxtd / halfpi) # print "interpolate", interpolate # if interpolate > 1.0: # vertices = self.interpolate(vertices, interpolate) -# result = npy.zeros((len(vertices) * 3 - 2, 2), npy.float_) -# codes = mpath.Path.CURVE4 * npy.ones((len(vertices) * 3 - 2, ), mpath.Path.code_type) +# result = np.zeros((len(vertices) * 3 - 2, 2), np.float_) +# codes = mpath.Path.CURVE4 * np.ones((len(vertices) * 3 - 2, ), mpath.Path.code_type) # result[0] = vertices[0] # codes[0] = mpath.Path.MOVETO -# kappa = 4.0 * ((npy.sqrt(2.0) - 1.0) / 3.0) -# tkappa = npy.arctan(kappa) -# hyp_kappa = npy.sqrt(kappa*kappa + 1.0) +# kappa = 4.0 * ((np.sqrt(2.0) - 1.0) / 3.0) +# tkappa = np.arctan(kappa) +# hyp_kappa = np.sqrt(kappa*kappa + 1.0) # t0 = vertices[0:-1, 0] # t1 = vertices[1: , 0] # r0 = vertices[0:-1, 1] # r1 = vertices[1: , 1] -# td = npy.where(t1 > t0, t1 - t0, twopi - (t0 - t1)) -# td_scaled = td / (npy.pi * 0.5) +# td = np.where(t1 > t0, t1 - t0, twopi - (t0 - t1)) +# td_scaled = td / (np.pi * 0.5) # rd = r1 - r0 # r0kappa = r0 * kappa * td_scaled # r1kappa = r1 * kappa * td_scaled @@ -593,11 +593,11 @@ # result[1::3, 0] = t0 + (tkappa * td_scaled) # result[1::3, 1] = r0*hyp_kappa -# # result[1::3, 1] = r0 / npy.cos(tkappa * td_scaled) # npy.sqrt(r0*r0 + ravg_kappa*ravg_kappa) +# # result[1::3, 1] = r0 / np.cos(tkappa * td_scaled) # np.sqrt(r0*r0 + ravg_kappa*ravg_kappa) # result[2::3, 0] = t1 - (tkappa * td_scaled) # result[2::3, 1] = r1*hyp_kappa -# # result[2::3, 1] = r1 / npy.cos(tkappa * td_scaled) # npy.sqrt(r1*r1 + ravg_kappa*ravg_kappa) +# # result[2::3, 1] = r1 / np.cos(tkappa * td_scaled) # np.sqrt(r1*r1 + ravg_kappa*ravg_kappa) # result[3::3, 0] = t1 # result[3::3, 1] = r1 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |