pythonmatplotlib

matplotlib cm.get_cmap(name, num_steps)


My python code uses

plt.cm.getcmap("coolwarm", num_steps)

This causes a deprecation warning.

The get_cmap function was deprecated in Matplotlib 3.7 and will be removed in 3.11. Use matplotlib.colormaps[name] or matplotlib.colormaps.get_cmap() or pyplot.get_cmap() instead.

however - both suggested methods do not provide a "num_steps" parameter. How do I need to update my statement to be compatible?


Solution

  • In [29]: import matplotlib
        ...: 
        ...: cw = matplotlib.colormaps['coolwarm']
        ...: cw10 = matplotlib.colormaps['coolwarm'].resampled(10)
        ...: print(cw.N, cw10.N)
    256 10
    
    In [30]: