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

Skip to content

Commit 115a194

Browse files
committed
Numpified backend_bases.py
svn path=/trunk/matplotlib/; revision=3479
1 parent 156f3b2 commit 115a194

1 file changed

Lines changed: 27 additions & 31 deletions

File tree

lib/matplotlib/backend_bases.py

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@
88

99
import numpy as npy
1010
import matplotlib.numerix.npyma as ma
11-
12-
from cbook import is_string_like, enumerate, strip_math, Stack, CallbackRegistry
13-
from colors import colorConverter
14-
from numerix import array, sqrt, pi, log, asarray, ones, zeros, Float, Float32
15-
from numerix import arange, compress, take, isnan, any
16-
from patches import Rectangle
17-
from transforms import lbwh_to_bbox, identity_transform
18-
import widgets
11+
import matplotlib.cbook as cbook
12+
import matplotlib.colors as colors
13+
import matplotlib.transforms as transforms
14+
import matplotlib.widgets as widgets
1915

2016
class RendererBase:
2117
"""An abstract base class to handle drawing/rendering operations
@@ -141,7 +137,7 @@ def draw_line_collection(self, segments, transform, clipbox,
141137
"""
142138

143139
newstyle = getattr(self, 'draw_markers', None) is not None
144-
identity = identity_transform()
140+
identity = transforms.identity_transform()
145141
gc = self.new_gc()
146142
if clipbox is not None:
147143
gc.set_clip_rectangle(clipbox.get_bounds())
@@ -204,18 +200,18 @@ def draw_quad_mesh(self, meshWidth, meshHeight, colors,
204200
See documentation in QuadMesh class in collections.py for details
205201
"""
206202
# print "draw_quad_mesh not found, using function in backend_bases"
207-
verts = zeros(((meshWidth * meshHeight), 4, 2), Float32)
208-
indices = arange((meshWidth + 1) * (meshHeight + 1))
209-
indices = compress((indices + 1) % (meshWidth + 1), indices)
203+
verts = npy.zeros(((meshWidth * meshHeight), 4, 2), npy.float32)
204+
indices = npy.arange((meshWidth + 1) * (meshHeight + 1))
205+
indices = npy.compress((indices + 1) % (meshWidth + 1), indices)
210206
indices = indices[:(meshWidth * meshHeight)]
211-
verts[:, 0, 0] = take(xCoords, indices)
212-
verts[:, 0, 1] = take(yCoords, indices)
213-
verts[:, 1, 0] = take(xCoords, (indices + 1))
214-
verts[:, 1, 1] = take(yCoords, (indices + 1))
215-
verts[:, 2, 0] = take(xCoords, (indices + meshWidth + 2))
216-
verts[:, 2, 1] = take(yCoords, (indices + meshWidth + 2))
217-
verts[:, 3, 0] = take(xCoords, (indices + meshWidth + 1))
218-
verts[:, 3, 1] = take(yCoords, (indices + meshWidth + 1))
207+
verts[:, 0, 0] = npy.take(xCoords, indices)
208+
verts[:, 0, 1] = npy.take(yCoords, indices)
209+
verts[:, 1, 0] = npy.take(xCoords, (indices + 1))
210+
verts[:, 1, 1] = npy.take(yCoords, (indices + 1))
211+
verts[:, 2, 0] = npy.take(xCoords, (indices + meshWidth + 2))
212+
verts[:, 2, 1] = npy.take(yCoords, (indices + meshWidth + 2))
213+
verts[:, 3, 0] = npy.take(xCoords, (indices + meshWidth + 1))
214+
verts[:, 3, 1] = npy.take(yCoords, (indices + meshWidth + 1))
219215
if (showedges):
220216
edgecolors = colors
221217
else:
@@ -262,7 +258,7 @@ def draw_poly_collection(
262258

263259
for i in xrange(N):
264260
polyverts = ma.filled(verts[i % Nverts], npy.nan)
265-
if any(isnan(polyverts)):
261+
if npy.any(npy.isnan(polyverts)):
266262
continue
267263
linewidth = linewidths[i % Nlw]
268264
rf,gf,bf,af = facecolors[i % Nface]
@@ -337,8 +333,8 @@ def draw_regpoly_collection(
337333
gc.set_clip_rectangle(clipbox.get_bounds())
338334

339335
xverts, yverts = zip(*verts)
340-
xverts = asarray(xverts)
341-
yverts = asarray(yverts)
336+
xverts = npy.asarray(xverts)
337+
yverts = npy.asarray(yverts)
342338

343339
Nface = len(facecolors)
344340
Nedge = len(edgecolors)
@@ -423,7 +419,7 @@ def get_text_extent(self, text): # is not used, can be removed?
423419
"""
424420
Get the text extent in window coords
425421
"""
426-
return lbwh_to_bbox(0,0,1,1) # your values here
422+
return transforms.lbwh_to_bbox(0,0,1,1) # your values here
427423

428424
def get_text_width_height(self, s, prop, ismath):
429425
"""
@@ -452,7 +448,7 @@ def points_to_pixels(self, points):
452448
return points
453449

454450
def strip_math(self, s):
455-
return strip_math(s)
451+
return cbook.strip_math(s)
456452

457453

458454
class GraphicsContextBase:
@@ -618,7 +614,7 @@ def set_foreground(self, fg, isRGB=False):
618614
if isRGB:
619615
self._rgb = fg
620616
else:
621-
self._rgb = colorConverter.to_rgb(fg)
617+
self._rgb = colors.colorConverter.to_rgb(fg)
622618

623619
def set_graylevel(self, frac):
624620
"""
@@ -870,7 +866,7 @@ def __init__(self, figure):
870866
figure.set_canvas(self)
871867
self.figure = figure
872868
# a dictionary from event name to a dictionary that maps cid->func
873-
self.callbacks = CallbackRegistry(self.events)
869+
self.callbacks = cbook.CallbackRegistry(self.events)
874870
self.widgetlock = widgets.LockDraw()
875871
self._button = None # the button pressed
876872
self._key = None # the key pressed
@@ -1174,8 +1170,8 @@ def __init__(self, canvas):
11741170
self.canvas = canvas
11751171
canvas.toolbar = self
11761172
# a dict from axes index to a list of view limits
1177-
self._views = Stack()
1178-
self._positions = Stack() # stack of subplot positions
1173+
self._views = cbook.Stack()
1174+
self._positions = cbook.Stack() # stack of subplot positions
11791175
self._xypress = None # the location and axis info at the time of the press
11801176
self._idPress = None
11811177
self._idRelease = None
@@ -1529,15 +1525,15 @@ def release_zoom(self, event):
15291525
a.set_ylim((ymin, ymax))
15301526
elif self._button_pressed == 3:
15311527
if a.get_xscale()=='log':
1532-
alpha=log(Xmax/Xmin)/log(xmax/xmin)
1528+
alpha=npy.log(Xmax/Xmin)/npy.log(xmax/xmin)
15331529
x1=pow(Xmin/xmin,alpha)*Xmin
15341530
x2=pow(Xmax/xmin,alpha)*Xmin
15351531
else:
15361532
alpha=(Xmax-Xmin)/(xmax-xmin)
15371533
x1=alpha*(Xmin-xmin)+Xmin
15381534
x2=alpha*(Xmax-xmin)+Xmin
15391535
if a.get_yscale()=='log':
1540-
alpha=log(Ymax/Ymin)/log(ymax/ymin)
1536+
alpha=npy.log(Ymax/Ymin)/npy.log(ymax/ymin)
15411537
y1=pow(Ymin/ymin,alpha)*Ymin
15421538
y2=pow(Ymax/ymin,alpha)*Ymin
15431539
else:

0 commit comments

Comments
 (0)