Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 52cb510

Browse files
committed
Change "import numpy as npy" to common convention "import numpy as np"
svn path=/trunk/matplotlib/; revision=8292
1 parent 3819fad commit 52cb510

8 files changed

Lines changed: 82 additions & 83 deletions

File tree

lib/matplotlib/backends/backend_agg.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"""
2323
from __future__ import division
2424

25-
import numpy as npy
25+
import numpy as np
2626

2727
from matplotlib import verbose, rcParams
2828
from matplotlib.backend_bases import RendererBase,\
@@ -99,10 +99,10 @@ def draw_path(self, gc, path, transform, rgbFace=None):
9999
npts = path.vertices.shape[0]
100100
if (nmax > 100 and npts > nmax and path.should_simplify and
101101
rgbFace is None and gc.get_hatch() is None):
102-
nch = npy.ceil(npts/float(nmax))
103-
chsize = int(npy.ceil(npts/nch))
104-
i0 = npy.arange(0, npts, chsize)
105-
i1 = npy.zeros_like(i0)
102+
nch = np.ceil(npts/float(nmax))
103+
chsize = int(np.ceil(npts/nch))
104+
i0 = np.arange(0, npts, chsize)
105+
i1 = np.zeros_like(i0)
106106
i1[:-1] = i0[1:] - 1
107107
i1[-1] = npts
108108
for ii0, ii1 in zip(i0, i1):
@@ -196,7 +196,7 @@ def draw_tex(self, gc, x, y, s, prop, angle):
196196
im = self.texd.get(key)
197197
if im is None:
198198
Z = texmanager.get_grey(s, size, self.dpi)
199-
Z = npy.array(Z * 255.0, npy.uint8)
199+
Z = np.array(Z * 255.0, np.uint8)
200200

201201
self._renderer.draw_text_image(Z, x, y, angle, gc)
202202

@@ -339,7 +339,7 @@ def post_processing(image, dpi):
339339
self._update_methods()
340340

341341
if w > 0 and h > 0:
342-
img = npy.fromstring(buffer, npy.uint8)
342+
img = np.fromstring(buffer, np.uint8)
343343
img, ox, oy = post_processing(img.reshape((h, w, 4)) / 255.,
344344
self.dpi)
345345
image = fromarray(img, 1)

lib/matplotlib/backends/backend_cairo.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from __future__ import division
2222
import os, sys, warnings, gzip
2323

24-
import numpy as npy
24+
import numpy as np
2525

2626
def _fn_name(): return sys._getframe(1).f_code.co_name
2727

@@ -196,7 +196,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
196196

197197
ctx.save()
198198
if angle:
199-
ctx.rotate (-angle * npy.pi / 180)
199+
ctx.rotate (-angle * np.pi / 180)
200200
ctx.set_font_size (size)
201201
ctx.show_text (s.encode("utf-8"))
202202
ctx.restore()
@@ -211,7 +211,7 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle):
211211
ctx.save()
212212
ctx.translate(x, y)
213213
if angle:
214-
ctx.rotate (-angle * npy.pi / 180)
214+
ctx.rotate (-angle * np.pi / 180)
215215

216216
for font, fontsize, s, ox, oy in glyphs:
217217
ctx.new_path()
@@ -355,7 +355,7 @@ def set_dashes(self, offset, dashes):
355355
self.ctx.set_dash([], 0) # switch dashes off
356356
else:
357357
self.ctx.set_dash (
358-
self.renderer.points_to_pixels (npy.asarray(dashes)), offset)
358+
self.renderer.points_to_pixels (np.asarray(dashes)), offset)
359359

360360

361361
def set_foreground(self, fg, isRGB=None):
@@ -469,7 +469,7 @@ def _save (self, fo, format, **kwargs):
469469
ctx = renderer.gc.ctx
470470

471471
if orientation == 'landscape':
472-
ctx.rotate (npy.pi/2)
472+
ctx.rotate (np.pi/2)
473473
ctx.translate (0, -height_in_points)
474474
# cairo/src/cairo_ps_surface.c
475475
# '%%Orientation: Portrait' is always written to the file header

lib/matplotlib/backends/backend_gdk.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def fn_name(): return sys._getframe(1).f_code.co_name
1616
% (gtk.pygtk_version + pygtk_version_required))
1717
del pygtk_version_required
1818

19-
import numpy as npy
19+
import numpy as np
2020

2121
import matplotlib
2222
from matplotlib._pylab_helpers import Gcf
@@ -109,7 +109,7 @@ def draw_image(self, gc, x, y, im):
109109
im.flipud_out()
110110
rows, cols, image_str = im.as_rgba_str()
111111

112-
image_array = npy.fromstring(image_str, npy.uint8)
112+
image_array = np.fromstring(image_str, np.uint8)
113113
image_array.shape = rows, cols, 4
114114

115115
pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,
@@ -174,13 +174,13 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle):
174174
N = imw * imh
175175

176176
# a numpixels by num fonts array
177-
Xall = npy.zeros((N,1), npy.uint8)
177+
Xall = np.zeros((N,1), np.uint8)
178178

179179
image_str = font_image.as_str()
180-
Xall[:,0] = npy.fromstring(image_str, npy.uint8)
180+
Xall[:,0] = np.fromstring(image_str, np.uint8)
181181

182182
# get the max alpha at each pixel
183-
Xs = npy.amax(Xall,axis=1)
183+
Xs = np.amax(Xall,axis=1)
184184

185185
# convert it to it's proper shape
186186
Xs.shape = imh, imw
@@ -381,7 +381,7 @@ def set_dashes(self, dash_offset, dash_list):
381381
if dash_list == None:
382382
self.gdkGC.line_style = gdk.LINE_SOLID
383383
else:
384-
pixels = self.renderer.points_to_pixels(npy.asarray(dash_list))
384+
pixels = self.renderer.points_to_pixels(np.asarray(dash_list))
385385
dl = [max(1, int(round(val))) for val in pixels]
386386
self.gdkGC.set_dashes(dash_offset, dl)
387387
self.gdkGC.line_style = gdk.LINE_ON_OFF_DASH

lib/matplotlib/backends/backend_pdf.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import warnings
1414
import zlib
1515

16-
import numpy as npy
16+
import numpy as np
1717

1818
from cStringIO import StringIO
1919
from datetime import datetime
@@ -136,7 +136,7 @@ def pdfRepr(obj):
136136
# need to use %f with some precision. Perhaps the precision
137137
# should adapt to the magnitude of the number?
138138
elif isinstance(obj, float):
139-
if not npy.isfinite(obj):
139+
if not np.isfinite(obj):
140140
raise ValueError, "Can only output finite numbers in PDF"
141141
r = "%.10f" % obj
142142
return r.rstrip('0').rstrip('.')
@@ -1088,8 +1088,8 @@ def writeGouraudTriangles(self):
10881088
shape = points.shape
10891089
flat_points = points.reshape((shape[0] * shape[1], 2))
10901090
flat_colors = colors.reshape((shape[0] * shape[1], 4))
1091-
points_min = npy.min(flat_points, axis=0) - (1 << 8)
1092-
points_max = npy.max(flat_points, axis=0) + (1 << 8)
1091+
points_min = np.min(flat_points, axis=0) - (1 << 8)
1092+
points_max = np.max(flat_points, axis=0) + (1 << 8)
10931093
factor = float(0xffffffff) / (points_max - points_min)
10941094

10951095
self.beginStream(
@@ -1105,7 +1105,7 @@ def writeGouraudTriangles(self):
11051105
0, 1, 0, 1, 0, 1]
11061106
})
11071107

1108-
streamarr = npy.empty(
1108+
streamarr = np.empty(
11091109
(shape[0] * shape[1],),
11101110
dtype=[('flags', 'u1'),
11111111
('points', '>u4', (2,)),
@@ -1137,21 +1137,21 @@ def imageObject(self, image):
11371137
def _rgb(self, im):
11381138
h,w,s = im.as_rgba_str()
11391139

1140-
rgba = npy.fromstring(s, npy.uint8)
1140+
rgba = np.fromstring(s, np.uint8)
11411141
rgba.shape = (h, w, 4)
11421142
rgb = rgba[:,:,:3]
11431143
a = rgba[:,:,3:]
11441144
return h, w, rgb.tostring(), a.tostring()
11451145

11461146
def _gray(self, im, rc=0.3, gc=0.59, bc=0.11):
11471147
rgbat = im.as_rgba_str()
1148-
rgba = npy.fromstring(rgbat[2], npy.uint8)
1148+
rgba = np.fromstring(rgbat[2], np.uint8)
11491149
rgba.shape = (rgbat[0], rgbat[1], 4)
1150-
rgba_f = rgba.astype(npy.float32)
1150+
rgba_f = rgba.astype(np.float32)
11511151
r = rgba_f[:,:,0]
11521152
g = rgba_f[:,:,1]
11531153
b = rgba_f[:,:,2]
1154-
gray = (r*rc + g*gc + b*bc).astype(npy.uint8)
1154+
gray = (r*rc + g*gc + b*bc).astype(np.uint8)
11551155
return rgbat[0], rgbat[1], gray.tostring()
11561156

11571157
def writeImages(self):
@@ -2005,9 +2005,9 @@ def delta(self, other):
20052005
try:
20062006
different = bool(ours != theirs)
20072007
except ValueError:
2008-
ours = npy.asarray(ours)
2009-
theirs = npy.asarray(theirs)
2010-
different = ours.shape != theirs.shape or npy.any(ours != theirs)
2008+
ours = np.asarray(ours)
2009+
theirs = np.asarray(theirs)
2010+
different = ours.shape != theirs.shape or np.any(ours != theirs)
20112011
if different:
20122012
break
20132013

lib/matplotlib/backends/backend_ps.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def _fn_name(): return sys._getframe(1).f_code.co_name
3636
from matplotlib.backends.backend_mixed import MixedModeRenderer
3737

3838

39-
import numpy as npy
39+
import numpy as np
4040
import binascii
4141
import re
4242
try:
@@ -127,7 +127,7 @@ def seq_allequal(seq1, seq2):
127127
#ok, neither are None:, assuming iterable
128128

129129
if len(seq1) != len(seq2): return False
130-
return npy.alltrue(npy.equal(seq1, seq2))
130+
return np.alltrue(np.equal(seq1, seq2))
131131

132132

133133
class RendererPS(RendererBase):
@@ -348,20 +348,20 @@ def _rgba(self, im):
348348
def _rgb(self, im):
349349
h,w,s = im.as_rgba_str()
350350

351-
rgba = npy.fromstring(s, npy.uint8)
351+
rgba = np.fromstring(s, np.uint8)
352352
rgba.shape = (h, w, 4)
353353
rgb = rgba[:,:,:3]
354354
return h, w, rgb.tostring()
355355

356356
def _gray(self, im, rc=0.3, gc=0.59, bc=0.11):
357357
rgbat = im.as_rgba_str()
358-
rgba = npy.fromstring(rgbat[2], npy.uint8)
358+
rgba = np.fromstring(rgbat[2], np.uint8)
359359
rgba.shape = (rgbat[0], rgbat[1], 4)
360-
rgba_f = rgba.astype(npy.float32)
360+
rgba_f = rgba.astype(np.float32)
361361
r = rgba_f[:,:,0]
362362
g = rgba_f[:,:,1]
363363
b = rgba_f[:,:,2]
364-
gray = (r*rc + g*gc + b*bc).astype(npy.uint8)
364+
gray = (r*rc + g*gc + b*bc).astype(np.uint8)
365365
return rgbat[0], rgbat[1], gray.tostring()
366366

367367
def _hex_lines(self, s, chars_per_line=128):
@@ -811,14 +811,14 @@ def draw_gouraud_triangles(self, gc, points, colors, trans):
811811
shape = points.shape
812812
flat_points = points.reshape((shape[0] * shape[1], 2))
813813
flat_colors = colors.reshape((shape[0] * shape[1], 4))
814-
points_min = npy.min(flat_points, axis=0) - (1 << 8)
815-
points_max = npy.max(flat_points, axis=0) + (1 << 8)
814+
points_min = np.min(flat_points, axis=0) - (1 << 8)
815+
points_max = np.max(flat_points, axis=0) + (1 << 8)
816816
factor = float(0xffffffff) / (points_max - points_min)
817817

818818
xmin, ymin = points_min
819819
xmax, ymax = points_max
820820

821-
streamarr = npy.empty(
821+
streamarr = np.empty(
822822
(shape[0] * shape[1],),
823823
dtype=[('flags', 'u1'),
824824
('points', '>u4', (2,)),
@@ -1492,7 +1492,7 @@ def get_bbox_header(l, b, r, t):
14921492
return a postscript header stringfor the given bbox (l, b, r, t)
14931493
"""
14941494

1495-
bbox_info = '%%%%BoundingBox: %d %d %d %d' % (l, b, npy.ceil(r), npy.ceil(t))
1495+
bbox_info = '%%%%BoundingBox: %d %d %d %d' % (l, b, np.ceil(r), np.ceil(t))
14961496
hires_bbox_info = '%%%%HiResBoundingBox: %.6f %.6f %.6f %.6f' % (l, b, r, t)
14971497

14981498
return '\n'.join([bbox_info, hires_bbox_info])
@@ -1537,7 +1537,7 @@ def get_bbox(tmpfile, bbox):
15371537
dy = (bbox[3]-bbox[1])/2
15381538
l,b,r,t = (x-dx, y-dy, x+dx, y+dy)
15391539

1540-
bbox_info = '%%%%BoundingBox: %d %d %d %d' % (l, b, npy.ceil(r), npy.ceil(t))
1540+
bbox_info = '%%%%BoundingBox: %d %d %d %d' % (l, b, np.ceil(r), np.ceil(t))
15411541
hires_bbox_info = '%%%%HiResBoundingBox: %.6f %.6f %.6f %.6f' % (l, b, r, t)
15421542

15431543
return '\n'.join([bbox_info, hires_bbox_info])

lib/matplotlib/backends/backend_wx.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696

9797

9898
import sys, os, os.path, math, StringIO, weakref, warnings
99-
import numpy as npy
99+
import numpy as np
100100

101101
# Debugging settings here...
102102
# Debug level set here. If the debug level is less than 5, information
@@ -417,7 +417,7 @@ def draw_image(self, gc, x, y, im):
417417
w=self.width
418418
h=self.height
419419
rows, cols, image_str = im.as_rgba_str()
420-
image_array = npy.fromstring(image_str, npy.uint8)
420+
image_array = np.fromstring(image_str, np.uint8)
421421
image_array.shape = rows, cols, 4
422422
bitmap = wx.BitmapFromBufferRGBA(cols,rows,image_array)
423423
gc = self.get_gc()

lib/matplotlib/mathtext.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3033,7 +3033,6 @@ def to_png(self, filename, texstr, color='black', dpi=120, fontsize=14):
30333033
Returns the offset of the baseline from the bottom of the
30343034
image in pixels.
30353035
"""
3036-
30373036
rgba, depth = self.to_rgba(texstr, color=color, dpi=dpi, fontsize=fontsize)
30383037
numrows, numcols, tmp = rgba.shape
30393038
_png.write_png(rgba.tostring(), numcols, numrows, filename)

0 commit comments

Comments
 (0)