Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Bug]: regression with ScalarMappable and.set_array andautoscale_None #20902

Closed
Milestone
@ryandvmartin

Description

@ryandvmartin

Bug summary

We are creating manualScalarMappable instances in some cases where colorbar creation is detached from the plotting event. Changed in#20511 an element-wise comparison of the color array is made, however, withScalarMappable.set_array there appears to be no assurances that the._A attribute will support such comparison.

Code for reproduction

importmatplotlibasmplimportmatplotlib.pyplotaspltnorm=mpl.colors.LogNorm()cmap=mpl.cm.get_cmap("viridis")fig,ax=plt.subplots()pts=mpl.cm.ScalarMappable(norm=norm,cmap=cmap)pts.set_array([0.1,0.9])plt.colorbar(pts)

Actual outcome

---------------------------------------------------------------------------TypeError                                 Traceback (most recent call last)<ipython-input-1-adec5b1bbfd1> in <module>      6 pts = mpl.cm.ScalarMappable(norm=norm, cmap=cmap)      7 pts.set_array([0.1, 0.9])----> 8 plt.colorbar(pts)~/rms-python/envs/mpl34/lib/python3.7/site-packages/matplotlib/pyplot.py in colorbar(mappable, cax, ax, **kw)   2354                                'an image (with imshow) or a contour set ('   2355                                'with contourf).')-> 2356     ret = gcf().colorbar(mappable, cax=cax, ax=ax, **kw)   2357     return ret   2358~/rms-python/envs/mpl34/lib/python3.7/site-packages/matplotlib/figure.py in colorbar(self, mappable, cax, ax, use_gridspec, **kw)   1174                              'panchor']   1175         cb_kw = {k: v for k, v in kw.items() if k not in NON_COLORBAR_KEYS}-> 1176         cb = cbar.Colorbar(cax, mappable, **cb_kw)   1177   1178         self.sca(current_ax)~/rms-python/envs/mpl34/lib/python3.7/site-packages/matplotlib/colorbar.py in __init__(self, ax, mappable, **kwargs)   1170         # even if mappable.draw has not yet been called.   1171         if mappable.get_array() is not None:-> 1172             mappable.autoscale_None()   1173   1174         self.mappable = mappable~/rms-python/envs/mpl34/lib/python3.7/site-packages/matplotlib/cm.py in autoscale_None(self)    474         if self._A is None:    475             raise TypeError('You must first set_array for mappable')--> 476         self.norm.autoscale_None(self._A)    477         self.changed()    478~/rms-python/envs/mpl34/lib/python3.7/site-packages/matplotlib/colors.py in autoscale_None(self, A)   1541     def autoscale_None(self, A):   1542         # docstring inherited.-> 1543         super().autoscale_None(np.ma.array(A, mask=(A <= 0)))   1544   1545TypeError: '<=' not supported between instances of 'list' and 'int'

Expected outcome

No error.

Operating system

Ubuntu

Matplotlib Version

3.4.3

Matplotlib Backend

agg

Python version

3.7.10

Jupyter version

NA

Other libraries

numpy 1.18.5

Installation

conda

Conda channel

conda-forge

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp