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

Regression with numpy ~~1.13~~ 1.14 for colorbars of boolean data #8820

Closed
krischer opened this issue Jun 29, 2017 · 12 comments

Comments

Projects
None yet
8 participants
@krischer
Copy link
Contributor

commented Jun 29, 2017

I'm not even sure if this is a feature that is supposed to work but matplotlib with numpy < 1.13 could plot colorbars for boolean data. It was not a true categorical colorbar but it did the job and was useful to have a around.

The following code works with numpy < 1.13:

import numpy as np
import matplotlib.pyplot as plt

plt.pcolor(np.array([[True, False], [False, True]]))
plt.colorbar()
plt.show()

figure_1

With numpy 1.13 the following exception is raised:

Traceback (most recent call last):
  File "binary_patch_example.py", line 5, in <module>
    plt.colorbar()
  File "/Users/lion/.miniconda/envs/salvus_mesher_py36/lib/python3.6/site-packages/matplotlib/pyplot.py", line 2261, in colorbar
    ret = gcf().colorbar(mappable, cax = cax, ax=ax, **kw)
  File "/Users/lion/.miniconda/envs/salvus_mesher_py36/lib/python3.6/site-packages/matplotlib/figure.py", line 1603, in colorbar
    cb = cbar.colorbar_factory(cax, mappable, **kw)
  File "/Users/lion/.miniconda/envs/salvus_mesher_py36/lib/python3.6/site-packages/matplotlib/colorbar.py", line 1347, in colorbar_factory
    cb = Colorbar(cax, mappable, **kwargs)
  File "/Users/lion/.miniconda/envs/salvus_mesher_py36/lib/python3.6/site-packages/matplotlib/colorbar.py", line 926, in __init__
    ColorbarBase.__init__(self, ax, **kw)
  File "/Users/lion/.miniconda/envs/salvus_mesher_py36/lib/python3.6/site-packages/matplotlib/colorbar.py", line 326, in __init__
    self.draw_all()
  File "/Users/lion/.miniconda/envs/salvus_mesher_py36/lib/python3.6/site-packages/matplotlib/colorbar.py", line 347, in draw_all
    self._process_values()
  File "/Users/lion/.miniconda/envs/salvus_mesher_py36/lib/python3.6/site-packages/matplotlib/colorbar.py", line 686, in _process_values
    expander=0.1)
  File "/Users/lion/.miniconda/envs/salvus_mesher_py36/lib/python3.6/site-packages/matplotlib/transforms.py", line 2786, in nonsingular
    elif vmax - vmin <= maxabsvalue * tiny:
TypeError: numpy boolean subtract, the `-` operator, is deprecated, use the bitwise_xor, the `^` operator, or the logical_xor function instead.
@jenshnielsen

This comment has been minimized.

Copy link
Member

commented Jun 29, 2017

There has been some discussion on the numpy of reverting this as it's caused a number of issues see https://mail.python.org/pipermail/numpy-discussion/2017-June/076903.html

@anntzer

This comment has been minimized.

Copy link
Contributor

commented Jun 29, 2017

Things should probably have been casted to floats at that point, otherwise we can also get issues with unsigned integer data...
(i.e. I think that's something we need to fix on our side)

@tacaswell

This comment has been minimized.

Copy link
Member

commented Jun 29, 2017

If we cast as float we discard units.

@anntzer

This comment has been minimized.

Copy link
Contributor

commented Jun 29, 2017

Hopefully units will have been stripped off by the time we reach transform.nonsingular. Yes, we could fix the issue in that specific function, but it seems smarter to do it as much upstream as possible.

@krischer

This comment has been minimized.

Copy link
Contributor Author

commented Jul 21, 2017

NumPy has reverted the removal of the boolean binary - operator so this works again with NumPy 1.13.1.

https://github.com/numpy/numpy/blob/master/doc/release/1.13.1-notes.rst

I'm leaving this open as you seem to still want to change some things somewhere else but feel free to close this as my original issue has been resolved by the latest numpy.

@tacaswell

This comment has been minimized.

Copy link
Member

commented Jul 21, 2017

Great!

Going to close this as it is only present in 1 numpy patch version and doing anything about it on our side would require more invasive type checking than we really want to do.

@tacaswell tacaswell closed this Jul 21, 2017

@hovren

This comment has been minimized.

Copy link

commented Jan 15, 2018

I am getting this error on NumPy 1.14 and matplotlib 2.1.1.

@jklymak

This comment has been minimized.

Copy link
Contributor

commented Jan 15, 2018

This exact error? Did numpy un-revert their unreversion?

@jklymak

This comment has been minimized.

Copy link
Contributor

commented Jan 15, 2018

https://github.com/numpy/numpy/releases

Using np.bool_ objects in place of integers is deprecated. Previously operator.index(np.bool_) was legal and allowed constructs such as [1, 2, 3][np.True_]. That was misleading, as it behaved differently from np.array([1, 2, 3])[np.True_].

I can't confirm this because 1.14 hasn't worked its way to conda for me yet...

As an obvious work around cast to int.

@hovren

This comment has been minimized.

Copy link

commented Jan 15, 2018

Yes, it is the exact same error/traceback. Tested with miniconda under Python 3.6. Reverting to numpy 13.3 makes the problem go away.

@tacaswell tacaswell added this to the v2.2 milestone Jan 15, 2018

@jklymak jklymak changed the title Regression with numpy 1.13 for colorbars of boolean data Regression with numpy ~~1.13~~ 1.14 for colorbars of boolean data Jan 15, 2018

@efiring efiring removed this from the v2.2 milestone Jan 22, 2018

@jklymak

This comment has been minimized.

Copy link
Contributor

commented Jan 22, 2018

Numpy changed this, and we decided to not fix their semantics; it'd require going through the whole code base and checking for bool, and thats a bit onerous for what is largely an edge case. So please cast to int (ahem or feel free to submit a PR across the code base 😉)

@jklymak jklymak closed this Jan 22, 2018

@dopplershift

This comment has been minimized.

Copy link
Contributor

commented Jan 22, 2018

To be clear, the workaround should look like:

arr = np.array([[True, False], [False, True]])
arr = arr.astype(np.int)

r4lv added a commit to r4lv/VIP that referenced this issue May 9, 2018

r4lv added a commit to r4lv/VIP that referenced this issue May 14, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.