| Hello, How would I create a specific cmap, which would have a separate color value for each matrix value? For example, could I make a cmap that specifies 0:'red', 1:'green', 2:'yellow', etc? The linear interpolation cmaps don't work as I want them to because they normalize to the given range of the matrix. Thank you. |
| I seem to recall once having a slick workaround for this but for the life of me I can't find it now. Anyway, something like this should get the job done: This should generate one very ugly graph: one red cell, two green cells, three yellow cells, four orange cells, and a brown cell at (6,6) in a purple sea. It's easy to bundle this into a function if you find yourself doing it frequently. [update: modified to make it slightly more general: now you don't need any ordering relation defined on the matrix elements]
Will that work even with Sage #s, like $4.3+2*I$?
kcrisman (Dec 20 '10)
This is exactly what I wanted! Thank you! This should be built in to Sage.
Eviatar Bach (Dec 20 '10)
I've updated the relevant ticket to put this as an enhancement. DSM may want to put his/her real name on there to get some credit if this ever makes it into Sage, which seems like a good idea.
kcrisman (Dec 21 '10) |
| Well, after writing this, I finally found out that we have this capability, though there are no examples in the This relies on Still, I'll put some other interesting resources I found below, in case that is too easy, or you need more direction for how to create good colormaps.. Here is an example of how this might be done in pure Python, and here is a nice way to 'discretize' colormaps. Now, these don't do exactly what you want, because the colormaps seem to mostly operate on the principle of the interval $(0,1)$. If we do So here is something that might work:
And I do not believe matplotlib allows one to associate specific numbers with colors, only the range. The type of cmap this provides is discrete, though, so hopefully it should be good enough if you know what values to expect ahead of time. If that is random, you may have to generate the cmap on the fly. The links provided are just some of some great posts and explanations I found on the matplotlib and Scipy websites, so hopefully you'll find what you need if this isn't it.
kcrisman (Dec 20 '10)
This fits my needs if normalized, but since user input will not necessarily be in order, the other solution works better.
Eviatar Bach (Dec 20 '10) |
| You might check out the |
Asked: Dec 19 '10
Seen: 239 times
Last updated: Dec 22 '10
powered by ASKBOT version 0.7.22
Copyright Sage, 2010. Some rights reserved under creative commons license.