pylab.imshow() does not handle clip_path properly

This is a bug report for matplotlib version 0.99.1.1

The clip_path keyword of imshow() does not work when setting it to (Path, Transform) for two reasons:

1. On line 622 of artist.py, v is now the tuple (Path,Transform) and should be apply to func with apply(func,v). Hence the following suggested change:

          for k,v in props.items():
              func = getattr(self, 'set_'+k, None)
              if func is None or not callable(func):
                  raise AttributeError('Unknown property %s'%k)
< func(v)
> if type(v) is tuple:
> apply(func,v)
              else:
                  func(v)
              changed = True

2. On line 6278 of axes.py, im.set_clip_path(self.patch) should not overwrite the clip path if already set. Hence the following suggested change:

          im.set_data(X)
          im.set_alpha(alpha)
          self._set_artist_props(im)
< im.set_clip_path(self.patch)
> if not im._clipon:
> im.set_clip_path(self.patch)
          #if norm is None and shape is None:
          # im.set_clim(vmin, vmax)
          if vmin is not None or vmax is not None:
              im.set_clim(vmin, vmax)
          else:
              im.autoscale_None()
          im.set_url(url)

Gellule Xg wrote:

This is a bug report for matplotlib version 0.99.1.1

The clip_path keyword of imshow() does not work when setting it to
(Path, Transform) for two reasons:

Hi, Thanks for the report. Do you have a simple test script that we can
use to see the problem and then fix it? We will then use this as the
basis to create a test function to make sure the issue never "crops" up
again.

-Andrew

Gellule Xg wrote:

This is a bug report for matplotlib version 0.99.1.1

The clip_path keyword of imshow() does not work when setting it to (Path, Transform) for two reasons:

1. On line 622 of artist.py, v is now the tuple (Path,Transform) and should be apply to func with apply(func,v). Hence the following suggested change:

          for k,v in props.items():
              func = getattr(self, 'set_'+k, None)
              if func is None or not callable(func):
                  raise AttributeError('Unknown property %s'%k)
< func(v)
> if type(v) is tuple:
> apply(func,v)
              else:
                  func(v)

apply is deprecated. The block above could be written in one line as

                 func(*tuple(v))

Eric

···

              changed = True

2. On line 6278 of axes.py, im.set_clip_path(self.patch) should not overwrite the clip path if already set. Hence the following suggested change:

          im.set_data(X)
          im.set_alpha(alpha)
          self._set_artist_props(im)
< im.set_clip_path(self.patch)
> if not im._clipon:
> im.set_clip_path(self.patch)
          #if norm is None and shape is None:
          # im.set_clim(vmin, vmax)
          if vmin is not None or vmax is not None:
              im.set_clim(vmin, vmax)
          else:
              im.autoscale_None()
          im.set_url(url)

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
matplotlib-devel List Signup and Options

This is a bug report for matplotlib version 0.99.1.1

The clip_path keyword of imshow() does not work when setting it to (Path, Transform) for two reasons:

Hi, Thanks for the report. Do you have a simple test script that we can
use to see the problem and then fix it? We will then use this as the
basis to create a test function to make sure the issue never "crops" up
again.

-Andrew

Hi Andrew,
Please try the following. It's a script that clips an NxN image based on its contour.
Thanks,
-Julien

import numpy
import pylab

#Create a NxN image
N=100
(x,y) = numpy.indices((N,N))
x -= N/2
y -= N/2
r = numpy.sqrt(x**2+y**2-x*y)

#Create a contour plot at N/4 and extract both the clip path and transform
c=pylab.contour(r,[N/4])
clipPath = c.collections[0].get_paths()[0]
clipTransform = c.collections[0].get_transform()

#Plot the image clipped by the contour
pylab.imshow(r, clip_path=(clipPath,clipTransform))
pylab.show()

Gellule Xg wrote:

This is a bug report for matplotlib version 0.99.1.1

The clip_path keyword of imshow() does not work when setting it to (Path, Transform) for two reasons:
      

Hi, Thanks for the report. Do you have a simple test script that we can
use to see the problem and then fix it? We will then use this as the
basis to create a test function to make sure the issue never "crops" up
again.

-Andrew
    
Hi Andrew,
Please try the following. It's a script that clips an NxN image based on its contour.
Thanks,
-Julien
  

Hi Julien,

I made a couple fixes to MPL 0.99 maintenance branch and then added a modified version your example in the tests. See matplotlib download | SourceForge.net

You should be able to use this approach to do what you were originally after.

My actual fixes to MPL were in r7866 and r7867. I had to take a slightly different approach than your suggestion. The approach I implemented based on your initial patch doesn't access private variables or change the way calling setters methods works.

-Andrew