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

Skip to content

Commit 93676b7

Browse files
committed
Make safezip accept more args; quadmesh_demo cleanup
svn path=/trunk/matplotlib/; revision=4114
1 parent 8369c9c commit 93676b7

2 files changed

Lines changed: 22 additions & 19 deletions

File tree

examples/quadmesh_demo.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,26 @@
22
"""
33
pcolormesh uses a QuadMesh, a faster generalization of pcolor, but
44
with some restrictions.
5+
6+
This demo illustrates a bug in quadmesh with masked data.
57
"""
68

7-
import numpy as nx
8-
from pylab import figure,show
9+
import numpy as npy
10+
from matplotlib.pyplot import figure, show
911
from matplotlib import cm, colors
12+
from matplotlib.numerix import npyma as ma
1013

1114
n = 56
12-
x = nx.linspace(-1.5,1.5,n)
13-
X,Y = nx.meshgrid(x,x);
14-
Qx = nx.cos(Y) - nx.cos(X)
15-
Qz = nx.sin(Y) + nx.sin(X)
15+
x = npy.linspace(-1.5,1.5,n)
16+
X,Y = npy.meshgrid(x,x);
17+
Qx = npy.cos(Y) - npy.cos(X)
18+
Qz = npy.sin(Y) + npy.sin(X)
1619
Qx = (Qx + 1.1)
17-
Z = nx.sqrt(X**2 + Y**2)/5;
18-
Z = (Z - nx.amin(Z)) / (nx.amax(Z) - nx.amin(Z))
20+
Z = npy.sqrt(X**2 + Y**2)/5;
21+
Z = (Z - Z.min()) / (Z.max() - Z.min())
1922

2023
# The color array can include masked values:
21-
Zm = nx.ma.masked_where(nx.fabs(Qz) < 0.5*nx.amax(Qz), Z)
24+
Zm = ma.masked_where(npy.fabs(Qz) < 0.5*npy.amax(Qz), Z)
2225

2326

2427
fig = figure()

lib/matplotlib/cbook.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ def dedent(s):
557557
# expressions. However, this function accounted for almost 30% of
558558
# matplotlib startup time, so it is worthy of optimization at all
559559
# costs.
560-
560+
561561
if not s: # includes case of s is None
562562
return ''
563563

@@ -576,7 +576,7 @@ def dedent(s):
576576
if unindent is None:
577577
unindent = re.compile("\n\r? {0,%d}" % nshift)
578578
_dedent_regex[nshift] = unindent
579-
579+
580580
result = unindent.sub("\n", s).strip()
581581
return result
582582

@@ -844,15 +844,15 @@ def report_memory(i=0): # argument may go away
844844

845845
return mem
846846

847+
_safezip_msg = 'In safezip, len(args[0])=%d but len(args[%d])=%d'
848+
def safezip(*args):
849+
'make sure args are equal len before zipping'
850+
Nx = len(args[0])
851+
for i, arg in enumerate(args[1:]):
852+
if len(arg) != Nx:
853+
raise ValueError(_safezip_msg % (Nx, i+1, len(arg)))
854+
return zip(*args)
847855

848-
def safezip(x, y):
849-
'make sure x and y are equal len before zipping'
850-
Nx = len(x)
851-
Ny = len(y)
852-
if Nx!=Ny:
853-
raise RuntimeError('x and y must be equal length; found len(x)=%d and len(y)=%d'%
854-
(Nx, Ny))
855-
return zip(x, y)
856856
class MemoryMonitor:
857857
def __init__(self, nmax=20000):
858858
self._nmax = nmax

0 commit comments

Comments
 (0)