sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.47k stars 487 forks source link

Use matplotlib's get_cmap to try to get a mpl colormap #21954

Open jasongrout opened 8 years ago

jasongrout commented 8 years ago

Currently, at https://github.com/sagemath/sage-prod/blob/1b1e6f608d1ef8ee664bb19e991efbbc68cbd51f/src/sage/plot/colors.py#L1393, we manually check colormap names against matplotlib's cmap.datad dictionary. The new viridis map is not in there, though. Instead, we should just use matplotlib.cm.get_cmap, and possibly catch the error (or let the error fall through) if there is no cmap with that name.

Example code that should work:

density_plot(x^2-y^2,(x,-2,2),(y,-2,2),cmap='viridis', aspect_ratio=1).show()

Current workaround - get the cmap ourselves:

import matplotlib
density_plot(x^2-y^2,(x,-2,2),(y,-2,2),cmap=matplotlib.cm.get_cmap('viridis'), aspect_ratio=1).show()

Component: graphics

Issue created by migration from https://trac.sagemath.org/ticket/21954

jasongrout commented 8 years ago
comment:1

https://github.com/sagemath/sage-prod/blob/1b1e6f608d1ef8ee664bb19e991efbbc68cbd51f/src/sage/plot/colors.py#L1442 should perhaps use cmap_d instead of datad as well.