Skip to content

Commit ad5a637

Browse files
committed
added some mlab imports back to pylab
svn path=/trunk/matplotlib/; revision=4223
1 parent f57d81b commit ad5a637

File tree

6 files changed

+92
-44
lines changed

6 files changed

+92
-44
lines changed

API_CHANGES

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
Moved mlab.csv2rec -> recutils.csv2rec
21

32
Added ax kwarg to pyplot.colorbar and Figure.colorbar so that
43
one can specify the axes object from which space for the colorbar

Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Makefile for matplotlib
22

3-
PYTHON = /usr/bin/python2.5
3+
PYTHON = `which python`
44
VERSION = `${PYTHON} setup.py --version`
55

66
DISTFILES = API_CHANGES KNOWN_BUGS INSTALL README TODO license \
@@ -12,11 +12,11 @@ RELEASE = matplotlib-${VERSION}
1212

1313
clean:
1414
${PYTHON} setup.py clean;\
15-
rm -f *.png *.ps *.eps *.svg *.jpg
15+
rm -f *.png *.ps *.eps *.svg *.jpg *.pdf
1616
find . -name "_tmp*.py" | xargs rm -f;\
1717
find . \( -name "*~" -o -name "*.pyc" \) | xargs rm -f;\
18-
find examples \( -name "*.svg" -o -name "*.png" -o -name "*.ps" -o -name "*.eps" -o -name "*.tar" -o -name "*.gz" -o -name "*.log" -o -name "*.aux" -o -name "*.tex" \) | xargs rm -f
19-
find unit \( -name "*.png" -o -name "*.ps" -o -name "*.eps" \) | xargs rm -f
18+
find examples \( -name "*.svg" C-o -name "*.png" -o -name "*.pdf" -o -name "*.ps" -o -name "*.eps" -o -name "*.tar" -o -name "*.gz" -o -name "*.log" -o -name "*.aux" -o -name "*.tex" \) | xargs rm -f
19+
find unit \( -name "*.png" -o -name "*.ps" -o -name "*.pdf" -o -name "*.eps" \) | xargs rm -f
2020
find . \( -name "#*" -o -name ".#*" -o -name ".*~" -o -name "*~" \) | xargs rm -f
2121

2222

lib/matplotlib/axes.py

+33
Original file line numberDiff line numberDiff line change
@@ -4798,6 +4798,39 @@ def table(self, **kwargs):
47984798
return mtable.table(self, **kwargs)
47994799
table.__doc__ = cbook.dedent(table.__doc__) % martist.kwdocd
48004800

4801+
def twinx(self):
4802+
"""
4803+
ax = twinx()
4804+
4805+
create a twin of Axes for generating a plot with a sharex
4806+
x-axis but independent y axis. The y-axis of self will have
4807+
ticks on left and the returned axes will have ticks on the
4808+
right
4809+
"""
4810+
4811+
ax2 = self.figure.add_axes(self.get_position(), sharex=self, frameon=False)
4812+
ax2.yaxis.tick_right()
4813+
ax2.yaxis.set_label_position('right')
4814+
self.yaxis.tick_left()
4815+
return ax2
4816+
4817+
def twiny(self):
4818+
"""
4819+
ax = twiny()
4820+
4821+
create a twin of Axes for generating a plot with a shared
4822+
y-axis but independent x axis. The x-axis of self will have
4823+
ticks on bottom and the returned axes will have ticks on the
4824+
top
4825+
"""
4826+
4827+
ax2 = self.figure.add_axes(self.get_position(), sharey=self, frameon=False)
4828+
ax2.xaxis.tick_top()
4829+
ax2.xaxis.set_label_position('top')
4830+
self.xaxis.tick_bottom()
4831+
return ax2
4832+
4833+
48014834
#### Data analysis
48024835

48034836

lib/matplotlib/mlab.py

+40-25
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,9 @@ def corrcoef(*args):
442442
kw = dict(rowvar=False)
443443
return npy.corrcoef(*args, **kw)
444444

445-
def polyfit(x,y,N):
445+
def polyfit(*args, **kwargs):
446446
"""
447+
def polyfit(x,y,N)
447448
448449
Do a best fit polynomial of order N of y to x. Return value is a
449450
vector of polynomial coefficients [pk ... p1 p0]. Eg, for N=2
@@ -480,21 +481,13 @@ def polyfit(x,y,N):
480481
See also polyval
481482
482483
"""
483-
x = npy.asarray(x, dtype=npy.float_)
484-
#y = npy.asarray(y, dtype=npy.float_)
485-
#y.shape = (len(y),1)
486-
#X = npy.matrix(npy.vander(x, N+1))
487-
#Xt = npy.matrix(X.transpose())
488-
#c = npy.array(npy.linalg.inv(Xt*X)*Xt*y) # convert back to array
489-
#c.shape = (N+1,)
490-
#return c
491-
X = npy.vander(x, N+1)
492-
return npy.linalg.lstsq(X, y)[0]
484+
warnings.warn("use numpy.poyfit", DeprecationWarning)
485+
return npy.polyfit(*args, **kw)
493486

494487

495488

496489

497-
def polyval(p,x):
490+
def polyval(*args, **kwargs):
498491
"""
499492
y = polyval(p,x)
500493
@@ -510,14 +503,11 @@ def polyval(p,x):
510503
See also polyfit
511504
512505
"""
513-
x = npy.asarray(x, dtype=npy.float_)
514-
p = npy.asarray(p, dtype=npy.float_).reshape((len(p),1))
515-
X = npy.vander(x,len(p))
516-
y = npy.dot(X,p)
517-
return y.reshape(x.shape)
506+
warnings.warn("use numpy.polyval", DeprecationWarning)
507+
return npy.polyval(*args, **kw)
518508

519509

520-
def vander(x,N=None):
510+
def vander(*args, **kwargs):
521511
"""
522512
X = vander(x,N=None)
523513
@@ -527,7 +517,7 @@ def vander(x,N=None):
527517
528518
"""
529519
warnings.warn("Use numpy.vander()", DeprecationWarning)
530-
return npy.vander(x, N)
520+
return npy.vander(*args, **kwargs)
531521

532522

533523
def donothing_callback(*args):
@@ -1262,20 +1252,31 @@ def load(fname,comments='#',delimiter=None, converters=None,skiprows=0,
12621252
fh = cbook.to_filehandle(fname)
12631253
X = []
12641254

1255+
if delimiter==' ':
1256+
# space splitting is a special case since x.split() is what
1257+
# you want, not x.split(' ')
1258+
def splitfunc(x):
1259+
return x.split()
1260+
else:
1261+
def splitfunc(x):
1262+
return x.split(delimiter)
1263+
1264+
1265+
12651266
converterseq = None
12661267
for i,line in enumerate(fh):
12671268
if i<skiprows: continue
12681269
line = line.split(comments, 1)[0].strip()
12691270
if not len(line): continue
12701271
if converterseq is None:
12711272
converterseq = [converters.get(j,float)
1272-
for j,val in enumerate(line.split(delimiter))]
1273+
for j,val in enumerate(splitfunc(line))]
12731274
if usecols is not None:
12741275
vals = line.split(delimiter)
12751276
row = [converterseq[j](vals[j]) for j in usecols]
12761277
else:
12771278
row = [converterseq[j](val)
1278-
for j,val in enumerate(line.split(delimiter))]
1279+
for j,val in enumerate(splitfunc(line))]
12791280
thisLen = len(row)
12801281
X.append(row)
12811282

@@ -2281,7 +2282,7 @@ def __init__(self, precision=4):
22812282
FormatFloat.__init__(self, precision, scale=1e-6)
22822283

22832284

2284-
class FormatDate(FormatString):
2285+
class FormatDate(FormatObj):
22852286
def __init__(self, fmt):
22862287
self.fmt = fmt
22872288

@@ -2301,7 +2302,7 @@ def __init__(self, fmt='%Y-%m-%d %H:%M:%S'):
23012302
npy.float32 : FormatFloat(),
23022303
npy.float64 : FormatFloat(),
23032304
npy.object_ : FormatObj(),
2304-
npy.string_ : FormatString(),
2305+
npy.string_ : FormatObj(),
23052306
}
23062307

23072308
def get_formatd(r, formatd=None):
@@ -2658,15 +2659,21 @@ def foreach(model, path, iter, selected):
26582659

26592660

26602661

2661-
def rec2gtk(r, formatd=None, rownum=0):
2662+
def rec2gtk(r, formatd=None, rownum=0, autowin=True):
26622663
"""
26632664
save record array r to excel pyExcelerator worksheet ws
26642665
starting at rownum. if ws is string like, assume it is a
26652666
filename and save to it
26662667
26672668
formatd is a dictionary mapping dtype name -> FormatXL instances
26682669
2669-
The next rownum after writing is returned
2670+
This function creates a SortedStringsScrolledWindow (derived
2671+
from gtk.ScrolledWindow) and returns it. if autowin is True,
2672+
a gtk.Window is created, attached to the
2673+
SortedStringsScrolledWindow instance, shown and returned. If
2674+
autowin=False, the caller is responsible for adding the
2675+
SortedStringsScrolledWindow instance to a gtk widget and
2676+
showing it.
26702677
"""
26712678

26722679

@@ -2692,6 +2699,14 @@ def rec2gtk(r, formatd=None, rownum=0):
26922699
for row in r:
26932700
scroll.add_row(row)
26942701

2702+
2703+
if autowin:
2704+
win = gtk.Window()
2705+
win.set_default_size(800,600)
2706+
win.add(scroll)
2707+
win.show_all()
2708+
scroll.win = win
2709+
26952710
return scroll
26962711

26972712

lib/matplotlib/pylab.py

+13
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,19 @@
249249
from numpy.random import *
250250
from numpy.linalg import *
251251

252+
from matplotlib.mlab import load, window_hanning, window_none, conv, detrend, demean, \
253+
detrend_mean, detrend_none, detrend_linear, entropy, normpdf, levypdf, \
254+
find, longest_contiguous_ones, longest_ones, prepca, prctile, prctile_rank, \
255+
center_matrix, rk4, bivariate_normal, get_xyz_where, get_sparse_matrix, dist, \
256+
dist_point_to_segment, segments_intersect, fftsurr, liaupunov, movavg, \
257+
save, load, slopes, stineman_interp, inside_poly, poly_below, poly_between, exp_safe, \
258+
amap, rms_flat, l1norm, l2norm, norm_flat, frange, diagonal_matrix, identity, \
259+
base_repr, binary_repr, log2, ispower2, fromfunction_kw, rem, norm, orth, rank, sqrtm,\
260+
mfuncC, approx_real, rec_append_field, rec_drop_fields, rec_join, csv2rec, rec2csv
261+
262+
263+
264+
252265
# old style--if True, override standard numpy with oldnumeric
253266
if False:
254267
from numpy.oldnumeric import array, zeros, shape, rank, size, fromstring,\

lib/matplotlib/pyplot.py

+2-14
Original file line numberDiff line numberDiff line change
@@ -492,14 +492,8 @@ def twinx(ax=None):
492492
"""
493493
if ax is None:
494494
ax=gca()
495-
496-
497-
ax2 = gcf().add_axes(ax.get_position(), sharex=ax, frameon=False)
498-
ax2.yaxis.tick_right()
499-
ax2.yaxis.set_label_position('right')
500-
ax.yaxis.tick_left()
501495
draw_if_interactive()
502-
return ax2
496+
return ax.twinx()
503497

504498

505499
def twiny(ax=None):
@@ -510,14 +504,8 @@ def twiny(ax=None):
510504
"""
511505
if ax is None:
512506
ax=gca()
513-
514-
515-
ax2 = gcf().add_axes(ax.get_position(), sharey=ax, frameon=False)
516-
ax2.xaxis.tick_top()
517-
ax2.xaxis.set_label_position('top')
518-
ax.xaxis.tick_bottom()
519507
draw_if_interactive()
520-
return ax2
508+
return ax.twiny()
521509

522510

523511

0 commit comments

Comments
 (0)