Closed
Description
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
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()
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.