small patch to enable formatters for contour line labels

The function “clabel” does not allow the use of formatters for the label; this small patch enables their use, so that one can pass in any subclass of ticker.Formatter in the ‘fmt’ argument.

Replace the following in contour.py:

def get_text(self, lev, fmt):
    "get the text of the label"
    if cbook.is_string_like(lev):
        return lev
    else:
        if isinstance(fmt,dict):
            return fmt[lev]

        else:
            return fmt%lev

With the following:

def get_text(self, lev, fmt):
    "get the text of the label"
    if cbook.is_string_like(lev):
        return lev

    else:
        if isinstance(fmt,dict):
            return fmt[lev]
        elif isinstance(fmt,ticker.Formatter):
            return fmt(lev)

        else:
            return fmt%lev

As you can see, there is only a two line change, but it does enable formatters. Perhaps one of the devs can put this in?

···


Daniel Hyams
dhyams@…1896…

The function "clabel" does not allow the use of formatters for the
label; this small patch enables their use, so that one can pass in any
subclass of ticker.Formatter in the 'fmt' argument.

Replace the following in contour.py:

    def get_text(self, lev, fmt):
"get the text of the label"
        if cbook.is_string_like(lev):
            return lev
        else:
            if isinstance(fmt,dict):
                return fmt[lev]
            else:
                return fmt%lev

With the following:

    def get_text(self, lev, fmt):
"get the text of the label"
        if cbook.is_string_like(lev):
            return lev
        else:
            if isinstance(fmt,dict):
                return fmt[lev]
          elif isinstance(fmt,ticker.Formatter):
                return fmt(lev)
            else:
                return fmt%lev

As you can see, there is only a two line change, but it does enable
formatters. Perhaps one of the devs can put this in?

Yes, I have it done at home, and when I am a little more confident I know how to interact with github, I will push it up.

Eric

···

On 02/20/2011 06:17 AM, Daniel Hyams wrote:


Daniel Hyams
dhyams@…287… <mailto:dhyams@…287…>

The function "clabel" does not allow the use of formatters for the
label; this small patch enables their use, so that one can pass in any
subclass of ticker.Formatter in the 'fmt' argument.

Replace the following in contour.py:

    def get_text(self, lev, fmt):
"get the text of the label"
        if cbook.is_string_like(lev):
            return lev
        else:
            if isinstance(fmt,dict):
                return fmt[lev]
            else:
                return fmt%lev

With the following:

    def get_text(self, lev, fmt):
"get the text of the label"
        if cbook.is_string_like(lev):
            return lev
        else:
            if isinstance(fmt,dict):
                return fmt[lev]
          elif isinstance(fmt,ticker.Formatter):
                return fmt(lev)
            else:
                return fmt%lev

As you can see, there is only a two line change, but it does enable
formatters. Perhaps one of the devs can put this in?

Done.

https://github.com/matplotlib/matplotlib/commit/9114598093984f39f40e50db9a8c15cfe1dc0d74

Eric

···

On 02/20/2011 06:17 AM, Daniel Hyams wrote:


Daniel Hyams
dhyams@…287… <mailto:dhyams@…287…>

Thanks Eric!

···

On Sun, Feb 20, 2011 at 9:02 PM, Eric Firing <efiring@...202...> wrote:

On 02/20/2011 06:17 AM, Daniel Hyams wrote:

The function "clabel" does not allow the use of formatters for the
label; this small patch enables their use, so that one can pass in any
subclass of ticker.Formatter in the 'fmt' argument.

Replace the following in contour.py:

def get\_text\(self, lev, fmt\):

"get the text of the label"
if cbook.is_string_like(lev):
return lev
else:
if isinstance(fmt,dict):
return fmt[lev]
else:
return fmt%lev

With the following:

def get\_text\(self, lev, fmt\):

"get the text of the label"
if cbook.is_string_like(lev):
return lev
else:
if isinstance(fmt,dict):
return fmt[lev]
elif isinstance(fmt,ticker.Formatter):
return fmt(lev)
else:
return fmt%lev

As you can see, there is only a two line change, but it does enable
formatters. Perhaps one of the devs can put this in?

Done.

https://github.com/matplotlib/matplotlib/commit/9114598093984f39f40e50db9a8c15cfe1dc0d74

Eric


Daniel Hyams
dhyams@…287… <mailto:dhyams@…287…>

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
Daniel Hyams
dhyams@...287...