taichi icon indicating copy to clipboard operation
taichi copied to clipboard

[Example] Update colormap access in euler.py to prevent MatplotlibDeprecationWarning

Open bluevisor opened this issue 1 year ago • 1 comments

Summary

This PR resolves a deprecation warning in euler.py that occurs when running ti example 6. The warning appears as follows: MatplotlibDeprecationWarning: 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.

Changes Made

  • Updated import statement:
from matplotlib import cm

to

from matplotlib import colormaps
  • Replaced:
cmap = cm.get_cmap(cmap_name)

with

cmap = colormaps[cmap_name]

Rationale

This change uses the updated API for accessing colormaps in Matplotlib, ensuring compatibility with Matplotlib 3.7+ and removing the deprecation warning.

Testing

  • Verified that the warning is resolved when running ti example 6 with the updated code.
  • Confirmed that the colormap functionality remains the same post-update.

bluevisor avatar Nov 10 '24 10:11 bluevisor