#5601: predefine colors in Sage
---------------------------+------------------------------------------------
Reporter: jason | Owner: was
Type: enhancement | Status: needs_review
Priority: minor | Milestone: sage-4.3
Component: graphics | Keywords:
Work_issues: | Author: Mitesh Patel
Reviewer: | Merged:
---------------------------+------------------------------------------------
Comment(by mpatel):
Replying to [comment:14 robertwb]:
> Is there a way to do some of this lazily, e.g. not import matplotlib at
startup?
The following is ad hoc, but it appears to work. I removed the global
import and the code that sets up the module-scope colormaps. To the
''end'' of `sage.plot.colors` I added
{{{
#!python
# matplotlib color maps, loaded on-demand.
class ColormapLoader(object):
def __init__(self, globs):
self.cm = None
for key in globs:
self.__setattr__(key, globs[key])
def __getattr__(self, name):
if name == '__path__':
return __path__
if not self.cm:
print 'loading matplotlib.cm'
from matplotlib import cm
self.cm = cm
try:
cmap = self.cm.__getattribute__(name)
except AttributeError:
raise AttributeError, 'no colormap with name %s' % name
self.__setattr__(name, cmap)
return cmap
colormaps = ColormapLoader(vars())
import sys
sys.modules['sage.plot.colors'] = colormaps
}}}
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/5601#comment:15>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=.