Thanks to visit codestin.com
Credit goes to github.com

Skip to content

imshow fails to plot boolean arrays #409

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
scottstanie opened this issue Mar 23, 2023 · 1 comment · Fixed by #410
Closed

imshow fails to plot boolean arrays #409

scottstanie opened this issue Mar 23, 2023 · 1 comment · Fixed by #410
Labels

Comments

@scottstanie
Copy link
Contributor

Description

imshow errors due to np.sign being applied to a boolean.

Steps to reproduce

A "Minimal, Complete and Verifiable Example" will make it much easier for maintainers to help you.

import proplot as pplt
import numpy as np
fig, ax = pplt.subplots()
ax.imshow(np.random.rand(5, 5).astype(bool))

Expected behavior: [What you expected to happen]

Actual behavior: [What actually happened]

---------------------------------------------------------------------------
UFuncTypeError                            Traceback (most recent call last)
Cell In[9], line 2
      1 fig, ax = pplt.subplots()
----> 2 ax.imshow(np.random.rand(5, 5).astype(bool))

File /u/aurora-r0/staniewi/repos/proplot/proplot/internals/inputs.py:292, in _preprocess_or_redirect.<locals>._decorator.<locals>._preprocess_or_redirect(self, *args, **kwargs)
    289             ureg.setup_matplotlib(True)
    291 # Call main function
--> 292 return func(self, *args, **kwargs)

File /u/aurora-r0/staniewi/repos/proplot/proplot/axes/plot.py:4150, in PlotAxes.imshow(self, z, **kwargs)
   4146 """
   4147 %(plot.imshow)s
   4148 """
   4149 kw = kwargs.copy()
-> 4150 kw = self._parse_cmap(z, default_discrete=False, **kw)
   4151 guide_kw = _pop_params(kw, self._update_guide)
   4152 m = self._call_native('imshow', z, **kw)

File /u/aurora-r0/staniewi/repos/proplot/proplot/internals/warnings.py:110, in _rename_kwargs.<locals>._decorator.<locals>._deprecate_kwargs_wrapper(*args, **kwargs)
    105         key_new = key_new.format(value)
    106     _warn_proplot(
    107         f'Keyword {key_old!r} was deprecated in version {version} and may '
    108         f'be removed in {_next_release()}. Please use {key_new!r} instead.'
    109     )
--> 110 return func_orig(*args, **kwargs)

File /u/aurora-r0/staniewi/repos/proplot/proplot/axes/plot.py:2230, in PlotAxes._parse_cmap(self, cmap, cmap_kw, c, color, colors, norm, norm_kw, extend, vmin, vmax, vcenter, discrete, default_discrete, default_cmap, skip_autolev, min_levels, plot_lines, plot_contours, *args, **kwargs)
   2226     vmin, vmax, kwargs = self._parse_level_lim(
   2227         *args, vmin=vmin, vmax=vmax, **kwargs
   2228     )
   2229     if autodiverging and vmin is not None and vmax is not None:
-> 2230         if abs(np.sign(vmax) - np.sign(vmin)) == 2:
   2231             isdiverging = True
   2232 if discrete:

UFuncTypeError: ufunc 'sign' did not contain a loop with signature matching types <class 'numpy.dtype[bool_]'> -> None

Equivalent steps in matplotlib

# your code here, if applicable
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots()
ax.imshow(np.random.rand(5, 5).astype(bool))

Proplot version

Paste the results of import matplotlib; print(matplotlib.__version__); import proplot; print(proplot.version) here.

>>> import matplotlib; print(matplotlib.__version__); import proplot; print(proplot.version)
3.4.3
0.0.post4012

(I just forked the latest. Seems like the tags aren't visible, so setuptools_scm doesn't like it)

@scottstanie
Copy link
Contributor Author

I'm not sure if this is the best way to fix it, but adding a simple conversion to uint8 like #410 stops the error

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

Successfully merging a pull request may close this issue.

2 participants