Skip to content

Commit

Permalink
added some mlab imports back to pylab
Browse files Browse the repository at this point in the history
svn path=/trunk/matplotlib/; revision=4223
  • Loading branch information
jdh2358 committed Nov 12, 2007
1 parent f57d81b commit ad5a637
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 44 deletions.
1 change: 0 additions & 1 deletion API_CHANGES
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Moved mlab.csv2rec -> recutils.csv2rec

Added ax kwarg to pyplot.colorbar and Figure.colorbar so that
one can specify the axes object from which space for the colorbar
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Makefile for matplotlib

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

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

clean:
${PYTHON} setup.py clean;\
rm -f *.png *.ps *.eps *.svg *.jpg
rm -f *.png *.ps *.eps *.svg *.jpg *.pdf
find . -name "_tmp*.py" | xargs rm -f;\
find . \( -name "*~" -o -name "*.pyc" \) | xargs rm -f;\
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
find unit \( -name "*.png" -o -name "*.ps" -o -name "*.eps" \) | xargs rm -f
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
find unit \( -name "*.png" -o -name "*.ps" -o -name "*.pdf" -o -name "*.eps" \) | xargs rm -f
find . \( -name "#*" -o -name ".#*" -o -name ".*~" -o -name "*~" \) | xargs rm -f


Expand Down
33 changes: 33 additions & 0 deletions lib/matplotlib/axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4798,6 +4798,39 @@ def table(self, **kwargs):
return mtable.table(self, **kwargs)
table.__doc__ = cbook.dedent(table.__doc__) % martist.kwdocd

def twinx(self):
"""
ax = twinx()
create a twin of Axes for generating a plot with a sharex
x-axis but independent y axis. The y-axis of self will have
ticks on left and the returned axes will have ticks on the
right
"""

ax2 = self.figure.add_axes(self.get_position(), sharex=self, frameon=False)
ax2.yaxis.tick_right()
ax2.yaxis.set_label_position('right')
self.yaxis.tick_left()
return ax2

def twiny(self):
"""
ax = twiny()
create a twin of Axes for generating a plot with a shared
y-axis but independent x axis. The x-axis of self will have
ticks on bottom and the returned axes will have ticks on the
top
"""

ax2 = self.figure.add_axes(self.get_position(), sharey=self, frameon=False)
ax2.xaxis.tick_top()
ax2.xaxis.set_label_position('top')
self.xaxis.tick_bottom()
return ax2


#### Data analysis


Expand Down
65 changes: 40 additions & 25 deletions lib/matplotlib/mlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,9 @@ def corrcoef(*args):
kw = dict(rowvar=False)
return npy.corrcoef(*args, **kw)

def polyfit(x,y,N):
def polyfit(*args, **kwargs):
"""
def polyfit(x,y,N)
Do a best fit polynomial of order N of y to x. Return value is a
vector of polynomial coefficients [pk ... p1 p0]. Eg, for N=2
Expand Down Expand Up @@ -480,21 +481,13 @@ def polyfit(x,y,N):
See also polyval
"""
x = npy.asarray(x, dtype=npy.float_)
#y = npy.asarray(y, dtype=npy.float_)
#y.shape = (len(y),1)
#X = npy.matrix(npy.vander(x, N+1))
#Xt = npy.matrix(X.transpose())
#c = npy.array(npy.linalg.inv(Xt*X)*Xt*y) # convert back to array
#c.shape = (N+1,)
#return c
X = npy.vander(x, N+1)
return npy.linalg.lstsq(X, y)[0]
warnings.warn("use numpy.poyfit", DeprecationWarning)
return npy.polyfit(*args, **kw)




def polyval(p,x):
def polyval(*args, **kwargs):
"""
y = polyval(p,x)
Expand All @@ -510,14 +503,11 @@ def polyval(p,x):
See also polyfit
"""
x = npy.asarray(x, dtype=npy.float_)
p = npy.asarray(p, dtype=npy.float_).reshape((len(p),1))
X = npy.vander(x,len(p))
y = npy.dot(X,p)
return y.reshape(x.shape)
warnings.warn("use numpy.polyval", DeprecationWarning)
return npy.polyval(*args, **kw)


def vander(x,N=None):
def vander(*args, **kwargs):
"""
X = vander(x,N=None)
Expand All @@ -527,7 +517,7 @@ def vander(x,N=None):
"""
warnings.warn("Use numpy.vander()", DeprecationWarning)
return npy.vander(x, N)
return npy.vander(*args, **kwargs)


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

if delimiter==' ':
# space splitting is a special case since x.split() is what
# you want, not x.split(' ')
def splitfunc(x):
return x.split()
else:
def splitfunc(x):
return x.split(delimiter)



converterseq = None
for i,line in enumerate(fh):
if i<skiprows: continue
line = line.split(comments, 1)[0].strip()
if not len(line): continue
if converterseq is None:
converterseq = [converters.get(j,float)
for j,val in enumerate(line.split(delimiter))]
for j,val in enumerate(splitfunc(line))]
if usecols is not None:
vals = line.split(delimiter)
row = [converterseq[j](vals[j]) for j in usecols]
else:
row = [converterseq[j](val)
for j,val in enumerate(line.split(delimiter))]
for j,val in enumerate(splitfunc(line))]
thisLen = len(row)
X.append(row)

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


class FormatDate(FormatString):
class FormatDate(FormatObj):
def __init__(self, fmt):
self.fmt = fmt

Expand All @@ -2301,7 +2302,7 @@ def __init__(self, fmt='%Y-%m-%d %H:%M:%S'):
npy.float32 : FormatFloat(),
npy.float64 : FormatFloat(),
npy.object_ : FormatObj(),
npy.string_ : FormatString(),
npy.string_ : FormatObj(),
}

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



def rec2gtk(r, formatd=None, rownum=0):
def rec2gtk(r, formatd=None, rownum=0, autowin=True):
"""
save record array r to excel pyExcelerator worksheet ws
starting at rownum. if ws is string like, assume it is a
filename and save to it
formatd is a dictionary mapping dtype name -> FormatXL instances
The next rownum after writing is returned
This function creates a SortedStringsScrolledWindow (derived
from gtk.ScrolledWindow) and returns it. if autowin is True,
a gtk.Window is created, attached to the
SortedStringsScrolledWindow instance, shown and returned. If
autowin=False, the caller is responsible for adding the
SortedStringsScrolledWindow instance to a gtk widget and
showing it.
"""


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


if autowin:
win = gtk.Window()
win.set_default_size(800,600)
win.add(scroll)
win.show_all()
scroll.win = win

return scroll


13 changes: 13 additions & 0 deletions lib/matplotlib/pylab.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,19 @@
from numpy.random import *
from numpy.linalg import *

from matplotlib.mlab import load, window_hanning, window_none, conv, detrend, demean, \
detrend_mean, detrend_none, detrend_linear, entropy, normpdf, levypdf, \
find, longest_contiguous_ones, longest_ones, prepca, prctile, prctile_rank, \
center_matrix, rk4, bivariate_normal, get_xyz_where, get_sparse_matrix, dist, \
dist_point_to_segment, segments_intersect, fftsurr, liaupunov, movavg, \
save, load, slopes, stineman_interp, inside_poly, poly_below, poly_between, exp_safe, \
amap, rms_flat, l1norm, l2norm, norm_flat, frange, diagonal_matrix, identity, \
base_repr, binary_repr, log2, ispower2, fromfunction_kw, rem, norm, orth, rank, sqrtm,\
mfuncC, approx_real, rec_append_field, rec_drop_fields, rec_join, csv2rec, rec2csv




# old style--if True, override standard numpy with oldnumeric
if False:
from numpy.oldnumeric import array, zeros, shape, rank, size, fromstring,\
Expand Down
16 changes: 2 additions & 14 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,14 +492,8 @@ def twinx(ax=None):
"""
if ax is None:
ax=gca()


ax2 = gcf().add_axes(ax.get_position(), sharex=ax, frameon=False)
ax2.yaxis.tick_right()
ax2.yaxis.set_label_position('right')
ax.yaxis.tick_left()
draw_if_interactive()
return ax2
return ax.twinx()


def twiny(ax=None):
Expand All @@ -510,14 +504,8 @@ def twiny(ax=None):
"""
if ax is None:
ax=gca()


ax2 = gcf().add_axes(ax.get_position(), sharey=ax, frameon=False)
ax2.xaxis.tick_top()
ax2.xaxis.set_label_position('top')
ax.xaxis.tick_bottom()
draw_if_interactive()
return ax2
return ax.twiny()



Expand Down

0 comments on commit ad5a637

Please sign in to comment.