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

Skip to content

Commit ec4332d

Browse files
committed
Made contour auto level generation work with log color scale
svn path=/trunk/matplotlib/; revision=4081
1 parent 6d18129 commit ec4332d

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2007-10-31 Made log color scale easier to use with contourf;
2+
automatic level generation now works. - EF
3+
14
2007-10-24 Added ax kwarg to Figure.colorbar and pyplot.colorbar - EF
25

36
2007-10-19 Removed a gsave/grestore pair surrounding _draw_ps, which

lib/matplotlib/contour.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,15 @@ def __init__(self, ax, *args, **kwargs):
401401
self.antialiased = kwargs.get('antialiased', True)
402402
self.nchunk = kwargs.get('nchunk', 0)
403403
self.locator = kwargs.get('locator', None)
404+
if (isinstance(norm, colors.LogNorm)
405+
or isinstance(self.locator, ticker.LogLocator)):
406+
self.logscale = True
407+
if norm is None:
408+
norm = colors.LogNorm()
409+
if self.extend is not 'neither':
410+
raise ValueError('extend kwarg does not work yet with log scale')
411+
else:
412+
self.logscale = False
404413

405414
if self.origin is not None: assert(self.origin in
406415
['lower', 'upper', 'image'])
@@ -493,7 +502,10 @@ def _autolev(self, z, N):
493502
three levels to provide boundaries for both regions.
494503
'''
495504
if self.locator is None:
496-
self.locator = ticker.MaxNLocator(N+1)
505+
if self.logscale:
506+
self.locator = ticker.LogLocator()
507+
else:
508+
self.locator = ticker.MaxNLocator(N+1)
497509
locator = self.locator
498510
zmax = self.zmax
499511
zmin = self.zmin
@@ -503,7 +515,10 @@ def _autolev(self, z, N):
503515
if zmax >= lev[-1]:
504516
lev[-1] += zmargin
505517
if zmin <= lev[0]:
506-
lev[0] -= zmargin
518+
if self.logscale:
519+
lev[0] = 0.99 * zmin
520+
else:
521+
lev[0] -= zmargin
507522
self._auto = True
508523
if self.filled:
509524
return lev
@@ -589,6 +604,10 @@ def _contour_args(self, *args):
589604
raise TypeError("Too many arguments to %s; see help(%s)" % (fn,fn))
590605
self.zmax = ma.maximum(z)
591606
self.zmin = ma.minimum(z)
607+
if self.logscale and self.zmin <= 0:
608+
z = ma.masked_where(z <= 0, z)
609+
warnings.warn('Log scale: values of z <=0 have been masked')
610+
self.zmin = z.min()
592611
self._auto = False
593612
if self.levels is None:
594613
if Nargs == 1 or Nargs == 3:

0 commit comments

Comments
 (0)