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

Skip to content

Commit ee849fa

Browse files
committed
Add support for nonuniform grids to imshow.
svn path=/branches/transforms/; revision=4189
1 parent 181d589 commit ee849fa

2 files changed

Lines changed: 48 additions & 30 deletions

File tree

lib/matplotlib/axes.py

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4385,7 +4385,9 @@ def fill(self, *args, **kwargs):
43854385
#### plotting z(x,y): imshow, pcolor and relatives, contour
43864386

43874387

4388-
def imshow(self, X,
4388+
def imshow(self, I,
4389+
X = None,
4390+
Y = None,
43894391
cmap = None,
43904392
norm = None,
43914393
aspect=None,
@@ -4402,18 +4404,24 @@ def imshow(self, X,
44024404
**kwargs):
44034405
"""
44044406
4405-
IMSHOW(X, cmap=None, norm=None, aspect=None, interpolation=None,
4406-
alpha=1.0, vmin=None, vmax=None, origin=None, extent=None)
4407+
IMSHOW(I, X=None, Y=None, cmap=None, norm=None, aspect=None,
4408+
interpolation=None, alpha=1.0, vmin=None, vmax=None,
4409+
origin=None, extent=None)
44074410
4408-
IMSHOW(X) - plot image X to current axes, resampling to scale to axes
4409-
size (X may be numarray/Numeric array or PIL image)
4411+
IMSHOW(I) - plot image I to current axes, resampling to scale to axes
4412+
size (I may be numarray/Numeric array or PIL image)
44104413
4411-
IMSHOW(X, **kwargs) - Use keyword args to control image scaling,
4412-
colormapping etc. See below for details
4414+
IMSHOW(I, X, Y) - plot image I to current axes, with
4415+
nonuniform X and Y axes. (I, X and Y may be
4416+
numarray/Numeric array or PIL image)
4417+
4418+
IMSHOW(I, X, Y, **kwargs) - Use keyword args to control image
4419+
scaling, colormapping etc. See
4420+
below for details
44134421
44144422
4415-
Display the image in X to current axes. X may be a float array, a
4416-
uint8 array or a PIL image. If X is an array, X can have the following
4423+
Display the image in I to current axes. I may be a float array, a
4424+
uint8 array or a PIL image. If I is an array, I can have the following
44174425
shapes:
44184426
44194427
MxN : luminance (grayscale, float array only)
@@ -4425,6 +4433,10 @@ def imshow(self, X,
44254433
The value for each component of MxNx3 and MxNx4 float arrays should be
44264434
in the range 0.0 to 1.0; MxN float arrays may be normalised.
44274435
4436+
X and/or Y may be provided to specify a non-uniform image
4437+
grid. Each element of the X or Y arrays is the width or height
4438+
of the corresponding pixel in the given image.
4439+
44284440
A image.AxesImage instance is returned
44294441
44304442
The following kwargs are allowed:
@@ -4488,12 +4500,25 @@ def imshow(self, X,
44884500
if norm is not None: assert(isinstance(norm, mcolors.Normalize))
44894501
if cmap is not None: assert(isinstance(cmap, mcolors.Colormap))
44904502
if aspect is None: aspect = rcParams['image.aspect']
4491-
self.set_aspect(aspect)
4492-
im = mimage.AxesImage(self, cmap, norm, interpolation, origin, extent,
4493-
filternorm=filternorm,
4494-
filterrad=filterrad, **kwargs)
4495-
4496-
im.set_data(X)
4503+
# self.set_aspect(aspect)
4504+
4505+
if X is None and Y is None:
4506+
im = mimage.AxesImage(self, cmap, norm, interpolation, origin, extent,
4507+
filternorm=filternorm,
4508+
filterrad=filterrad, **kwargs)
4509+
4510+
im.set_data(I)
4511+
else:
4512+
if X is None:
4513+
X = npy.arange(I.shape[1])
4514+
if Y is None:
4515+
Y = npy.arange(I.shape[0])
4516+
im = mimage.NonUniformImage(self, cmap=cmap, norm=norm,
4517+
interpolation=interpolation,
4518+
origin=origin, extent=extent,
4519+
filternorm=filternorm,
4520+
filterrad=filterrad, **kwargs)
4521+
im.set_data(X, Y, I)
44974522
im.set_alpha(alpha)
44984523
self._set_artist_props(im)
44994524
im.set_clip_path(self.axesPatch)
@@ -4515,7 +4540,7 @@ def imshow(self, X,
45154540

45164541
return im
45174542

4518-
4543+
45194544
def _pcolorargs(self, funcname, *args):
45204545
if len(args)==1:
45214546
C = args[0]

lib/matplotlib/image.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ def __init__(self, ax,
7777
# reverse interp dict
7878
self._interpdr = dict([ (v,k) for k,v in self._interpd.items()])
7979

80-
if interpolation is None: interpolation = rcParams['image.interpolation']
81-
8280
self.set_interpolation(interpolation)
8381
self.axes = ax
8482

@@ -267,7 +265,7 @@ def set_interpolation(self, s):
267265
268266
ACCEPTS: ['bicubic' | 'bilinear' | 'blackman100' | 'blackman256' | 'blackman64', 'nearest' | 'sinc144' | 'sinc256' | 'sinc64' | 'spline16' | 'spline36']
269267
"""
270-
268+
if s is None: s = rcParams['image.interpolation']
271269
s = s.lower()
272270
if not self._interpd.has_key(s):
273271
raise ValueError('Illegal interpolation string')
@@ -317,17 +315,10 @@ def get_filterrad(self):
317315

318316
class NonUniformImage(AxesImage):
319317
def __init__(self, ax,
320-
cmap = None,
321-
norm = None,
322-
extent=None,
318+
**kwargs
323319
):
324320
AxesImage.__init__(self, ax,
325-
cmap = cmap,
326-
norm = norm,
327-
extent=extent,
328-
interpolation = 'nearest',
329-
origin = 'lower',
330-
)
321+
**kwargs)
331322

332323
def make_image(self, magnification=1.0):
333324
if self._A is None:
@@ -382,9 +373,11 @@ def set_array(self, *args):
382373
raise NotImplementedError('Method not supported')
383374

384375
def set_interpolation(self, s):
385-
if s != 'nearest':
376+
print s
377+
if s != None and s != 'nearest':
386378
raise NotImplementedError('Only nearest neighbor supported')
387-
379+
AxesImage.set_interpolation(self, s)
380+
388381
def get_extent(self):
389382
if self._A is None:
390383
raise RuntimeError('Must set data first')

0 commit comments

Comments
 (0)