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

Cannot initialize ColorbarBase without a norm. #3805

Closed
chebee7i opened this issue Nov 16, 2014 · 2 comments
Closed

Cannot initialize ColorbarBase without a norm. #3805

chebee7i opened this issue Nov 16, 2014 · 2 comments

Comments

@chebee7i
Copy link
Contributor

In 1.3.1, the following code used to work:

import matplotlib
import matplotlib.pyplot as plt
ax = plt.gca()
matplotlib.colorbar.ColorbarBase(ax, plt.cm.bone)

But now, I get an error:

/home/me/.virtualenvs/py27/matplotlib/lib/matplotlib/colorbar.py in _process_values(self, b)
    656             self.norm.vmin, self.norm.vmax = mtrans.nonsingular(self.norm.vmin,
    657                                                                 self.norm.vmax,
--> 658                                                                 expander=0.1)
    659             if not self.norm.scaled():
    660                 self.norm.vmin = 0

/home/me/.virtualenvs/py27/matplotlib/lib/matplotlib/transforms.py in nonsingular(vmin, vmax, expander, tiny, increasing)
   2640     returns -*expander*, *expander*.
   2641     '''
-> 2642     if (not np.isfinite(vmin)) or (not np.isfinite(vmax)):
   2643         return -expander, expander
   2644     swapped = False

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

The issue is that vmin and vmax are both None.

Using git bisect, I was able to track it down to e9f9e6c which relates to #2642. I'm not familiar enough with the matplotlib internals to know the overall intent here. Is this a regression or the new, preferred behavior? If so, how should I be modifying the code? @efiring, I'm guessing you'll figure this one out with a quick glance.

@chebee7i
Copy link
Contributor Author

I guess the modification I need is obvious:

norm = matplotlib.colors.Normalize(0,1)
matplotlib.colorbar.ColorbarBase(ax, cmap=plt.cm.bone, norm=norm)

@tacaswell
Copy link
Member

The full trace-back is

/home/tcaswell/other_source/matplotlib/lib/matplotlib/colorbar.py in __init__(self, ax, cmap, norm, alpha, values, boundaries, orientation, ticklocation, extend, spacing, ticks, format, drawedges, filled, extendfrac, extendrect, label)
    319         # The rest is in a method so we can recalculate when clim changes.
    320         self.config_axis()
--> 321         self.draw_all()
    322 
    323     def _extend_lower(self):

/home/tcaswell/other_source/matplotlib/lib/matplotlib/colorbar.py in draw_all(self)
    340         and do all the drawing.
    341         '''
--> 342         self._process_values()
    343         self._find_range()
    344         X, Y = self._mesh()

/home/tcaswell/other_source/matplotlib/lib/matplotlib/colorbar.py in _process_values(self, b)
    656             self.norm.vmin, self.norm.vmax = mtrans.nonsingular(self.norm.vmin,
    657                                                                 self.norm.vmax,
--> 658                                                                 expander=0.1)
    659             if not self.norm.scaled():
    660                 self.norm.vmin = 0

/home/tcaswell/other_source/matplotlib/lib/matplotlib/transforms.py in nonsingular(vmin, vmax, expander, tiny, increasing)
   2641     returns -*expander*, *expander*.
   2642     '''
-> 2643     if (not np.isfinite(vmin)) or (not np.isfinite(vmax)):
   2644         return -expander, expander
   2645     swapped = False

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

The issue on #2642 was that under some conditions vmax-vmin == 0 which was causing a divide by zero exception later. The fix was to add the nonsingular call which checks if the values are the same and expands them if needed, however it was added before the check to make sure than norm.vmin and norm.vmax are not None.

Should be fixed in #3808

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants