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

Skip to content

Commit 18501b6

Browse files
committed
converted many non-numpy relicts
svn path=/trunk/matplotlib/; revision=3575
1 parent d9f3fba commit 18501b6

22 files changed

Lines changed: 195 additions & 198 deletions

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2007-07-19 converted non-numpy relicts troughout the code
2+
13
2007-07-19 replaced the Python code in numerix/ by a minimal wrapper around
24
numpy that explicitly mentions all symbols that need to be
35
addressed for further numpification - NN

lib/matplotlib/axes3d.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ def get_proj(self):
309309

310310
viewM = proj3d.view_transformation(E,R,V)
311311
perspM = proj3d.persp_transformation(zfront,zback)
312-
M0 = nx.matrixmultiply(viewM,worldM)
313-
M = nx.matrixmultiply(perspM,M0)
312+
M0 = nx.dot(viewM,worldM)
313+
M = nx.dot(perspM,M0)
314314
return M
315315

316316
def mouse_init(self):

lib/matplotlib/axis.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import sys
99

1010
from numerix import arange, array, asarray, ones, zeros, \
11-
nonzero, take, Float, log10, logical_and, \
11+
nonzero, take, log10, logical_and, \
1212
dot, sin, cos, tan, pi, sqrt
1313

1414
from artist import Artist, setp
@@ -118,7 +118,7 @@ def get_children(self):
118118

119119
def contains(self, mouseevent):
120120
"""Test whether the mouse event occured in the Tick marks.
121-
121+
122122
This function always returns false. It is more useful to test if the
123123
axis as a whole contains the mouse rather than the set of tick marks.
124124
"""
@@ -492,7 +492,7 @@ class Axis(Artist):
492492
LABELPAD = 5
493493
OFFSETTEXTPAD = 3
494494

495-
def __str__(self):
495+
def __str__(self):
496496
return str(self.__class__).split('.')[-1] \
497497
+ "(%d,%d)"%self.axes.transAxes.xy_tup((0,0))
498498

@@ -657,7 +657,7 @@ def get_label(self):
657657
def get_offset_text(self):
658658
'Return the axis offsetText as a Text instance'
659659
return self.offsetText
660-
660+
661661
def get_pickradius(self):
662662
'Return the depth of the axis used by the picker'
663663
return self.pickradius
@@ -901,11 +901,11 @@ def set_minor_locator(self, locator):
901901
self.minor.locator = locator
902902
self.minor.locator.set_view_interval( self.get_view_interval() )
903903
self.minor.locator.set_data_interval( self.get_data_interval() )
904-
904+
905905
def set_pickradius(self, pickradius):
906906
"""
907907
Set the depth of the axis used by the picker
908-
908+
909909
ACCEPTS: a distance in points
910910
"""
911911
self.pickradius = pickradius
@@ -967,12 +967,12 @@ def zoom(self, direction):
967967

968968
class XAxis(Axis):
969969
__name__ = 'xaxis'
970-
970+
971971
def contains(self,mouseevent):
972972
"""Test whether the mouse event occured in the x axis.
973973
"""
974974
if callable(self._contains): return self._contains(self,mouseevent)
975-
975+
976976
xpixel,ypixel = mouseevent.x,mouseevent.y
977977
try:
978978
xaxes,yaxes = self.axes.transAxes.inverse_xy_tup((xpixel,ypixel))
@@ -1155,11 +1155,11 @@ class YAxis(Axis):
11551155

11561156
def contains(self,mouseevent):
11571157
"""Test whether the mouse event occurred in the y axis.
1158-
1158+
11591159
Returns T/F, {}
11601160
"""
11611161
if callable(self._contains): return self._contains(self,mouseevent)
1162-
1162+
11631163
xpixel,ypixel = mouseevent.x,mouseevent.y
11641164
try:
11651165
xaxes,yaxes = self.axes.transAxes.inverse_xy_tup((xpixel,ypixel))

lib/matplotlib/backends/backend_agg.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
import os, sys
7474
import matplotlib
7575
from matplotlib import verbose, rcParams
76-
from matplotlib.numerix import array, Float, zeros, transpose
76+
from numpy import array, zeros, transpose
7777
from matplotlib._image import fromarray
7878
from matplotlib._pylab_helpers import Gcf
7979
from matplotlib.backend_bases import RendererBase,\
@@ -154,8 +154,8 @@ def draw_line(self, gc, x1, y1, x2, y2):
154154
point in x, y
155155
"""
156156
if __debug__: verbose.report('RendererAgg.draw_line', 'debug-annoying')
157-
x = array([x1,x2], typecode=Float)
158-
y = array([y1,y2], typecode=Float)
157+
x = array([x1,x2], float)
158+
y = array([y1,y2], float)
159159
self._renderer.draw_lines(gc, x, y)
160160

161161

@@ -273,7 +273,7 @@ def draw_tex(self, gc, x, y, s, prop, angle):
273273
def func(x):
274274
return transpose(fliplr(x))
275275

276-
Z = zeros((n,m,4), typecode=Float)
276+
Z = zeros((n,m,4), float)
277277
Z[:,:,0] = func(r)
278278
Z[:,:,1] = func(g)
279279
Z[:,:,2] = func(b)

lib/matplotlib/backends/backend_agg2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import matplotlib.agg as agg
99

1010
from matplotlib import verbose
11-
from matplotlib.numerix import array, Float
11+
from numpy import array
1212

1313
from matplotlib._pylab_helpers import Gcf
1414
from matplotlib.backend_bases import RendererBase,\

lib/matplotlib/backends/backend_cairo.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def _fn_name(): return sys._getframe(1).f_code.co_name
3838
from matplotlib.cbook import enumerate, izip
3939
from matplotlib.figure import Figure
4040
from matplotlib.mathtext import math_parse_s_ft2font
41-
import matplotlib.numerix as numx
41+
import numpy as npy
4242
from matplotlib.transforms import Bbox
4343
from matplotlib import rcParams
4444

@@ -137,8 +137,8 @@ def draw_arc(self, gc, rgbFace, x, y, width, height, angle1, angle2,
137137
ctx.rotate(rotation)
138138
ctx.scale(width / 2.0, height / 2.0)
139139
ctx.new_sub_path()
140-
ctx.arc(0.0, 0.0, 1.0, numx.pi * angle1 / 180.,
141-
numx.pi * angle2 / 180.)
140+
ctx.arc(0.0, 0.0, 1.0, npy.pi * angle1 / 180.,
141+
npy.pi * angle2 / 180.)
142142
ctx.restore()
143143

144144
self._fill_and_stroke (ctx, rgbFace)
@@ -243,7 +243,7 @@ def draw_point(self, gc, x, y):
243243
# render by drawing a 0.5 radius circle
244244
ctx = gc.ctx
245245
ctx.new_path()
246-
ctx.arc (x, self.height - y, 0.5, 0, 2*numx.pi)
246+
ctx.arc (x, self.height - y, 0.5, 0, 2*npy.pi)
247247
self._fill_and_stroke (ctx, gc.get_rgb())
248248

249249

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

295295
ctx.save()
296296
if angle:
297-
ctx.rotate (-angle * numx.pi / 180)
297+
ctx.rotate (-angle * npy.pi / 180)
298298
ctx.set_font_size (size)
299299
ctx.show_text (s)
300300
ctx.restore()
@@ -304,7 +304,7 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle):
304304
if _debug: print '%s.%s()' % (self.__class__.__name__, _fn_name())
305305
# mathtext using the gtk/gdk method
306306

307-
#if numx.which[0] == "numarray":
307+
#if npy.which[0] == "numarray":
308308
# warnings.warn("_draw_mathtext() currently works for numpy, but "
309309
# "not numarray")
310310
# return
@@ -327,21 +327,21 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle):
327327
N = imw*imh
328328

329329
# a numpixels by num fonts array
330-
Xall = numx.zeros((N,len(fonts)), typecode=numx.UInt8)
330+
Xall = npy.zeros((N,len(fonts)), npy.uint8)
331331

332332
for i, font in enumerate(fonts):
333333
if angle == 90:
334334
font.horiz_image_to_vert_image() # <-- Rotate
335335
imw, imh, s = font.image_as_str()
336-
Xall[:,i] = numx.fromstring(s, numx.UInt8)
336+
Xall[:,i] = npy.fromstring(s, npy.uint8)
337337

338338
# get the max alpha at each pixel
339-
Xs = numx.mlab.max (Xall,1)
339+
Xs = npy.mlab.max (Xall,1)
340340

341341
# convert it to it's proper shape
342342
Xs.shape = imh, imw
343343

344-
pa = numx.zeros(shape=(imh,imw,4), typecode=numx.UInt8)
344+
pa = npy.zeros((imh,imw,4), npy.uint8)
345345
rgb = gc.get_rgb()
346346
pa[:,:,0] = int(rgb[0]*255)
347347
pa[:,:,1] = int(rgb[1]*255)
@@ -469,7 +469,7 @@ def set_dashes(self, offset, dashes):
469469
self.ctx.set_dash([], 0) # switch dashes off
470470
else:
471471
self.ctx.set_dash (
472-
self.renderer.points_to_pixels (numx.asarray(dashes)), offset)
472+
self.renderer.points_to_pixels (npy.asarray(dashes)), offset)
473473

474474

475475
def set_foreground(self, fg, isRGB=None):
@@ -593,7 +593,7 @@ def _save (self, fo, format, orientation, **kwargs):
593593
ctx = renderer.ctx
594594

595595
if orientation == 'landscape':
596-
ctx.rotate (numx.pi/2)
596+
ctx.rotate (npy.pi/2)
597597
ctx.translate (0, -height_in_points)
598598
# cairo/src/cairo_ps_surface.c
599599
# '%%Orientation: Portrait' is always written to the file header

lib/matplotlib/backends/backend_gd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ def draw_lines(self, gc, x, y):
115115
point in x, y
116116
"""
117117

118-
x = x.astype(nx.Int16)
119-
y = self.height*ones(y.shape, nx.Int16) - y.astype(nx.Int16)
118+
x = x.astype(nx.int16)
119+
y = self.height*ones(y.shape, nx.int16) - y.astype(nx.int16)
120120
style = self._set_gd_style(gc)
121121
self.im.lines( zip(x,y), style)
122122
self.flush_clip()

lib/matplotlib/backends/backend_gdk.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def fn_name(): return sys._getframe(1).f_code.co_name
2424
from matplotlib.figure import Figure
2525
from matplotlib.mathtext import math_parse_s_ft2font
2626
import matplotlib.numerix as numerix
27-
from matplotlib.numerix import asarray, fromstring, UInt8, zeros, \
27+
from matplotlib.numerix import asarray, fromstring, uint8, zeros, \
2828
where, transpose, nonzero, indices, ones, nx
2929

3030

@@ -106,7 +106,7 @@ def draw_image(self, x, y, im, bbox):
106106
im.flipud_out()
107107
rows, cols, image_str = im.as_rgba_str()
108108

109-
image_array = fromstring(image_str, UInt8)
109+
image_array = fromstring(image_str, uint8)
110110
image_array.shape = rows, cols, 4
111111

112112
pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,
@@ -144,8 +144,8 @@ def draw_line(self, gc, x1, y1, x2, y2):
144144

145145
def draw_lines(self, gc, x, y, transform=None):
146146
if gc.gdkGC.line_width > 0:
147-
x = x.astype(nx.Int16)
148-
y = self.height - y.astype(nx.Int16)
147+
x = x.astype(nx.int16)
148+
y = self.height - y.astype(nx.int16)
149149
self.gdkDrawable.draw_lines(gc.gdkGC, zip(x,y))
150150

151151

@@ -213,13 +213,13 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle):
213213
N = imw*imh
214214

215215
# a numpixels by num fonts array
216-
Xall = zeros((N,len(fonts)), typecode=UInt8)
216+
Xall = zeros((N,len(fonts)), uint8)
217217

218218
for i, font in enumerate(fonts):
219219
if angle == 90:
220220
font.horiz_image_to_vert_image() # <-- Rotate
221221
imw, imh, image_str = font.image_as_str()
222-
Xall[:,i] = fromstring(image_str, UInt8)
222+
Xall[:,i] = fromstring(image_str, uint8)
223223

224224
# get the max alpha at each pixel
225225
Xs = numerix.mlab.max(Xall,1)

lib/matplotlib/backends/backend_gtk.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ def fn_name(): return sys._getframe(1).f_code.co_name
2222
from matplotlib.cbook import is_string_like, enumerate
2323
from matplotlib.colors import colorConverter
2424
from matplotlib.figure import Figure
25-
import matplotlib.numerix as numerix
26-
from matplotlib.numerix import asarray, fromstring, UInt8, zeros, \
27-
where, transpose, nonzero, indices, ones, nx
25+
from numpy import asarray, fromstring, zeros, \
26+
where, transpose, nonzero, indices, ones
2827
from matplotlib.widgets import SubplotTool
2928

3029
from matplotlib import lines
@@ -156,7 +155,7 @@ class FigureCanvasGTK (gtk.DrawingArea, FigureCanvasBase):
156155
gdk.LEAVE_NOTIFY_MASK |
157156
gdk.POINTER_MOTION_MASK |
158157
gdk.POINTER_MOTION_HINT_MASK)
159-
158+
160159
def __init__(self, figure):
161160
if _debug: print 'FigureCanvasGTK.%s' % fn_name()
162161
FigureCanvasBase.__init__(self, figure)
@@ -1087,7 +1086,7 @@ def cb_cbox_changed (cbox, data=None):
10871086

10881087
hbox.show_all()
10891088
self.set_extra_widget(hbox)
1090-
1089+
10911090
def get_filename_from_user (self):
10921091
while True:
10931092
filename = None
@@ -1137,7 +1136,7 @@ class DialogLineprops:
11371136

11381137
def __init__(self, lines):
11391138
import gtk.glade
1140-
1139+
11411140
datadir = matplotlib.get_data_path()
11421141
gladefile = os.path.join(datadir, 'lineprops.glade')
11431142
if not os.path.exists(gladefile):
@@ -1279,7 +1278,7 @@ def on_dialog_lineprops_cancelbutton_clicked(self, button):
12791278
# Unfortunately, the SVG renderer (rsvg) leaks memory under earlier
12801279
# versions of pygtk, so we have to use a PNG file instead.
12811280
try:
1282-
1281+
12831282
if gtk.pygtk_version < (2, 8, 0):
12841283
icon_filename = 'matplotlib.png'
12851284
else:

lib/matplotlib/backends/backend_pdf.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from matplotlib.dviread import Dvi
2929
from matplotlib.ft2font import FT2Font, FIXED_WIDTH, ITALIC, LOAD_NO_SCALE
3030
from matplotlib.mathtext import math_parse_s_pdf
31-
from matplotlib.numerix import Float32, UInt8, fromstring, arange, infinity, isnan, asarray
31+
from numpy import float32, uint8, fromstring, arange, infinity, isnan, asarray
3232
from matplotlib.transforms import Bbox
3333
from matplotlib import ttconv
3434

@@ -543,13 +543,13 @@ def get_char_width(charcode):
543543
fontdict['FontMatrix'] = [ .001, 0, 0, .001, 0, 0 ]
544544
fontdict['CharProcs'] = charprocsObject
545545
fontdict['Encoding'] = {
546-
'Type': Name('Encoding'),
546+
'Type': Name('Encoding'),
547547
'Differences': differencesArray}
548548
elif fonttype == 42:
549549
fontdict['Subtype'] = Name('TrueType')
550550
fontdict['Encoding'] = Name('WinAnsiEncoding')
551551

552-
552+
553553
flags = 0
554554
symbolic = False #ps_name.name in ('Cmsy10', 'Cmmi10', 'Cmex10')
555555
if ff & FIXED_WIDTH: flags |= 1 << 0
@@ -632,7 +632,7 @@ def get_char_width(charcode):
632632
self.beginStream(charprocObject.id,
633633
None,
634634
{'Length': len(stream)})
635-
self.currentstream.write(stream)
635+
self.currentstream.write(stream)
636636
self.endStream()
637637
charprocs[charname] = charprocObject
638638
self.writeObject(charprocsObject, charprocs)
@@ -755,20 +755,20 @@ def imageObject(self, image):
755755
def _rgb(self, im):
756756
h,w,s = im.as_rgba_str()
757757

758-
rgba = fromstring(s, UInt8)
758+
rgba = fromstring(s, uint8)
759759
rgba.shape = (h, w, 4)
760760
rgb = rgba[:,:,:3]
761761
return h, w, rgb.tostring()
762762

763763
def _gray(self, im, rc=0.3, gc=0.59, bc=0.11):
764764
rgbat = im.as_rgba_str()
765-
rgba = fromstring(rgbat[2], UInt8)
765+
rgba = fromstring(rgbat[2], uint8)
766766
rgba.shape = (rgbat[0], rgbat[1], 4)
767-
rgba_f = rgba.astype(Float32)
767+
rgba_f = rgba.astype(float32)
768768
r = rgba_f[:,:,0]
769769
g = rgba_f[:,:,1]
770770
b = rgba_f[:,:,2]
771-
gray = (r*rc + g*gc + b*bc).astype(UInt8)
771+
gray = (r*rc + g*gc + b*bc).astype(uint8)
772772
return rgbat[0], rgbat[1], gray.tostring()
773773

774774
def writeImages(self):

0 commit comments

Comments
 (0)