Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added check in autoscale_None for completely masked pcolor plots. #2336

Merged
merged 2 commits into from Sep 27, 2013

Conversation

pelson
Copy link
Member

@pelson pelson commented Aug 23, 2013

Producing a pcolor of a completely masked array currently breaks v1.2.x with numpy 1.6:

import matplotlib.pyplot as plt
import numpy as np

data = np.ma.masked_all((12, 20))
plt.pcolor(data)
plt.show()

With the error:

Traceback (most recent call last):
  File "", line 7, in <module>
    plt.pcolor(data)
  File "matplotlib/pyplot.py", line 2758, in pcolor
    ret = ax.pcolor(*args, **kwargs)
  File "matplotlib/axes.py", line 7363, in pcolor
    collection.autoscale_None()
  File "matplotlib/cm.py", line 310, in autoscale_None
    self.norm.autoscale_None(self._A)
  File "matplotlib/colors.py", line 924, in autoscale_None
    self.vmin = ma.min(A)
  File "numpy/ma/core.py", line 5879, in min
    return asanyarray(obj).min(axis=axis, fill_value=fill_value, out=out)
  File "numpy/ma/core.py", line 5056, in min
    result = self.filled(fill_value).min(axis=axis, out=out).view(type(self))
ValueError: zero-size array to minimum.reduce without identity

This fix checks that the size of the array is >0 before checking the minimum value in autoscale_None.

@WeatherGod
Copy link
Member

This has bitten me before. Just for completeness, would be good to have a test for this case, I would also make sure the case of a completely masked array going in with vmin and/or vmax set, as that codepath has probably never been properly exercised.

@pelson
Copy link
Member Author

pelson commented Aug 23, 2013

I'd be looking to avoid a full graphics test. Thinking of just a plt.draw on a figure with the appropriate pcolor object containing fully masked data. Sound reasonable?

@WeatherGod
Copy link
Member

Whatever floats your boat!

@mdboom
Copy link
Member

mdboom commented Aug 26, 2013

👍 for me once the suggested test is in.

@dmcdougall
Copy link
Member

Ditto.

@pelson
Copy link
Member Author

pelson commented Sep 18, 2013

I've added a really simple test for this fix.

PLEASE NOTE: This PR is against v1.2.x. I'd be happy to target it against v1.3.x if needs be.

@mdboom
Copy link
Member

mdboom commented Sep 18, 2013

No worries. I can just merge this up to 1.3.x and master post-merge.

@mdboom
Copy link
Member

mdboom commented Sep 18, 2013

Once Travis has tested this, I'm fine with merging this.

@mdboom
Copy link
Member

mdboom commented Sep 26, 2013

This seems to have some issues on Python 3.

mdboom added a commit that referenced this pull request Sep 27, 2013
Added check in autoscale_None for completely masked pcolor plots.
@mdboom mdboom merged commit 49b73e7 into matplotlib:v1.2.x Sep 27, 2013
@pelson pelson deleted the completely_masked branch January 9, 2014 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants