Skip to content

Error when adding colorbar to pcolormesh of a boolean array #16420

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

Closed
blaylockbk opened this issue Feb 5, 2020 · 1 comment
Closed

Error when adding colorbar to pcolormesh of a boolean array #16420

blaylockbk opened this issue Feb 5, 2020 · 1 comment

Comments

@blaylockbk
Copy link

Bug report

Bug summary

The error

TypeError: numpy boolean subtract, the `-` operator, is deprecated, use the bitwise_xor, the `^` operator, or the logical_xor function instead.

occurs when adding a colorbar to a pcolormesh of a Boolean array.

Code for reproduction

import matplotlib.pyplot as plt
import numpy as np

x = np.random.rand(10,10)

b = x > .5

plt.pcolormesh(b)
plt.colorbar()

Actual outcome

image

Expected outcome

I'm not sure if this is really a bug, or if the error is by design, but I expected matplotlib to treat the bool array as 1s and 0s without intervention.
To get the colorbar to work, I changed the array dtype from bool to int.

import matplotlib.pyplot as plt
import numpy as np

x = np.random.rand(10,10)

b = np.array(x>.5, dtype=int)  # works as expected with this change

plt.pcolormesh(b)
plt.colorbar()

image

Matplotlib version

  • Operating system: Linux
  • Matplotlib version: 3.1.1
  • Matplotlib backend (print(matplotlib.get_backend())): module://ipykernel.pylab.backend_inline
  • Python version: 3.7.0
  • Jupyter version (if applicable): jupyterlab 1.2.6 (via conda-forge)
  • Other libraries:

Matplotlib installed via conda, default channel

Thanks for looking into this and I hope the feedback is useful.

@anntzer anntzer added this to the v3.2.0 milestone Feb 5, 2020
@anntzer
Copy link
Contributor

anntzer commented Feb 5, 2020

Thanks for the report. This was fixed recently in #16344 (mpl 3.2, should be released "soon").

@anntzer anntzer closed this as completed Feb 5, 2020
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