From: Eric F. <ef...@ha...> - 2007-04-18 08:52:23
|
James Boyle wrote: > I wish to make a color filled plot with the colors defined for > discrete, non-uniform intervals. Something like: > 0.0 -0.001 0.001-0.05 0.05-0.2 0.2-0.4 0.4-0.8 0.8-1.0 > red blue green magenta > yellow cyan > > with the colorbar labeled appropriately. > I have seen discussions and solutions for discrete colors but not for > non-uniform intervals + discrete. > The last post I saw regarding this type of issue was august 2005 - > and a solution was not resolved at that time. > However, Eric has done a huge amount of work in the intervening time > and a smarter person than myself might have a solution now. > > Note that I do not wish just to make contours - although that would > be good - but to have a general mapping code that joins allows the > color rmapping to be passed to colorbar. > maybe some sub-class of scalarMappable that could work. This is very easy for contourf, and is illustrated in the second figure made by examples/contourf_demo.py. For your case above, it would be something like levs = [0, 0.001, 0.05, 0.2, 0.4, 0.8, 1] colors = ['r', 'b', 'g', 'm', 'y', 'c'] contourf(z, levs, colors=colors) colorbar() Unfortunately, although it *should* be just as easy for imshow or pcolor, it is not at present; it can be done, probably in several ways, but not in such a transparent way. Attached is a quick attempt at something that might be close to what you need. The right way to do this is to make some changes and additions to colors.py and colorbar.py; I might get to that in a few days, or, more likely, it might be a few weeks. Eric > > Thanks for any help. > > --Jim |