cristobal-sifon / plottery

Plotting tools
GNU General Public License v3.0
0 stars 0 forks source link

colorscale seems to be outdated #22

Open cristobal-sifon opened 2 years ago

cristobal-sifon commented 2 years ago

in matplotlib 3.4.3 the following

colors, colormap = colorscale(array=array)
...
plt.colorbar(colormap)

does not work anymore, producing

Traceback (most recent call last):
  ...
  File "plot_relations.py", line 507, in plot_relation
    cbar = plt.colorbar(colormap)
  File "python3.9/site-packages/matplotlib/pyplot.py", line 2356, in colorbar
    ret = gcf().colorbar(mappable, cax=cax, ax=ax, **kw)
  File "python3.9/site-packages/matplotlib/figure.py", line 1176, in colorbar
    cb = cbar.Colorbar(cax, mappable, **cb_kw)
  File "python3.9/site-packages/matplotlib/colorbar.py", line 1172, in __init__
    mappable.autoscale_None()
  File "python3.9/site-packages/matplotlib/cm.py", line 476, in autoscale_None
    self.norm.autoscale_None(self._A)
  File "python3.9/site-packages/matplotlib/colors.py", line 1543, in autoscale_None
    super().autoscale_None(np.ma.array(A, mask=(A <= 0)))
TypeError: '<=' not supported between instances of 'list' and 'int'

(full file path hidden)

The following simplification of the code solves the issue:

colormap = cm.ScalarMappable(
            normfunc(vmin=array.min(), vmax=array.max()), cmap)
colors = colormap.to_rgba(array)

(where normfunc is either mplcolors.Normalize or mplcolors.LogNorm depending on the case), i.e., it seems set_array([]) is no longer needed.