#10503: Improve custom colormaps
---------------------------+------------------------------------------------
Reporter: kcrisman | Owner: jason, was
Type: enhancement | Status: new
Priority: minor | Milestone:
Component: graphics | Keywords: matplotlib, documentation
Author: | Upstream: N/A
Reviewer: | Merged:
Work_issues: |
---------------------------+------------------------------------------------
Description changed by kcrisman:
Old description:
> Apparently `matrix_plot?` isn't as helpful as it should be. See
> [http://ask.sagemath.org/question/265/specific-cmap this ask.sagemath.org
> question], where it wasn't obvious how to make a listed colormaps - this
> is buried in the `MatrixPlot` documentation.
New description:
At [http://ask.sagemath.org/question/265/specific-cmap this
ask.sagemath.org question], there is some good discussion of making custom
colormaps. 'DSM' gives the idea of the following, which 'Hypercube'
suggests we make a standard method:
{{{
# preamble
import matplotlib
# choose our preferred colour scheme, where None describes the exceptions
cdict = {0: 'red', 1: 'green', 2:'yellow', 3:'orange', 43+2*I: 'brown',
None: 'purple'}
# choose some fixed order -- doesn't matter what -- for iterating the keys
ckeys, cvals = zip(*cdict.items())
# build a mapping function to turn the matrix elements into integers
# (would be faster to use a dict for lots of colours)
cmap_fn = lambda x: Integer(ckeys.index(x if x in cdict else None))
# generate a colormap with exactly the colours we want, in the right order
my_cmap = matplotlib.colors.ListedColormap(cvals)
# generate a test matrix
m = Matrix(lambda i,j: (i+j) if (i,j) != (6,6) else 43+2*I, nrows=10)
# plot it: apply the mapping function to the matrix and feed matrix_plot
our colour map
matrix_plot(m.apply_map(cmap_fn), cmap=my_cmap)
}}}
Also, apparently `matrix_plot?` isn't as helpful as it should be. In the
same question, it wasn't obvious how to make a listed colormap - this is
buried in the `MatrixPlot` documentation.
--
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/10503#comment:1>
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=en.