Question

I'm using colorbar with the default "jet" map and use that with "hexbin". I have counts in my bins that range from 0 to about 1500. The problem is that the smallest values in some hexagonal bins are between 1 and 10, while some bins have counts of hundreds. This means that in the jet colormap, the 0 to 10 range comes up as the color 0 -- i.e. it is indistinguishable from a bin with 0 counts. I'd like those small values to be visible. How can I make colormap do something like: make sure that the bin values greater than or equal to N have a "visible", meaning different from the 0 bin, value in the color map?

thanks.

Was it helpful?

Solution

A quick fix could be try plotting log(counts) instead of counts on the hexbin -- this will spread the scale such that higher counts are compressed and lower counts are not. Note though, you'd have to put somewhere that the value being visualised is log(counts) not counts or else a casual reader would inariably misinterpret the graph.

A better method might be to modify the colour map that you're using. The in-built maps more or less change from the '0' colour to the '1' colour linearly. In order to make lower values have more spread in colour than the higher values, you need a non-linear colour map.

To do this you might try matplotlib.colors, and in particular matplotlib.colors.LinearSegmentedColormap.from_list (http://matplotlib.sourceforge.net/api/colors_api.html#matplotlib.colors.LinearSegmentedColormap.from_list)

Basically, you input the '0' and '1' colours (like blue-->red) and a gamma value. Having gamma > 1.0 increases sensitivity in the lower part of the scale.

If haven't tried, but something like:

import matplotlib.colors as colors
# colourmap from green to red, biased towards the blue end.
# Try out different gammas > 1.0
cmap = colors.LinearSegmentedColormap.from_list('nameofcolormap',['g','r'],gamma=2.0)

# feed cmap into hexbin
hexbin( ...., cmap=cmap )

OTHER TIPS

Also, there is the mincnt option to set the minimum count in hexbin, which leaves all bins with less than this number blank. This makes it very easy to distinguish between zero and one counts in the jet color scheme.

hexbin( ...., mincnt=1)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top