Skip to content

imshow fails to plot boolean arrays #409

Description

@scottstanie

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.

importproplotasppltimportnumpyasnpfig, ax=pplt.subplots()
ax.imshow(np.random.rand(5, 5).astype(bool))

Expected behavior: [What you expected to happen]

Actual behavior: [What actually happened]

---------------------------------------------------------------------------UFuncTypeErrorTraceback (mostrecentcalllast)
CellIn[9], line21fig, ax=pplt.subplots()
---->2ax.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)
289ureg.setup_matplotlib(True)
291# Call main function-->292returnfunc(self, *args, **kwargs)
File/u/aurora-r0/staniewi/repos/proplot/proplot/axes/plot.py:4150, inPlotAxes.imshow(self, z, **kwargs)
4146""" 4147 %(plot.imshow)s 4148 """4149kw=kwargs.copy()
->4150kw=self._parse_cmap(z, default_discrete=False, **kw)
4151guide_kw=_pop_params(kw, self._update_guide)
4152m=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)
105key_new=key_new.format(value)
106_warn_proplot(
107f'Keyword {key_old!r} was deprecated in version {version} and may '108f'be removed in {_next_release()}. Please use {key_new!r} instead.'109 )
-->110returnfunc_orig(*args, **kwargs)
File/u/aurora-r0/staniewi/repos/proplot/proplot/axes/plot.py:2230, inPlotAxes._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)
2226vmin, vmax, kwargs=self._parse_level_lim(
2227*args, vmin=vmin, vmax=vmax, **kwargs2228 )
2229ifautodivergingandvminisnotNoneandvmaxisnotNone:
->2230ifabs(np.sign(vmax) -np.sign(vmin)) ==2:
2231isdiverging=True2232ifdiscrete:
UFuncTypeError: ufunc'sign'didnotcontainaloopwithsignaturematchingtypes<class'numpy.dtype[bool_]'>->None

Equivalent steps in matplotlib

# your code here, if applicableimportmatplotlib.pyplotaspltimportnumpyasnpfig, 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions