[Biojava-l] Heat map gradients

Thomas Down thomas at derkholm.net
Mon Jun 7 06:14:35 EDT 2004


On Mon, Jun 07, 2004 at 12:00:19PM +0800, mark.schreiber at group.novartis.com wrote:
> Hi -
> 
> Slightly off topic but,
> 
> I am making an application that will display a heat map based on the value 
> of a variable. I'm wondering if anyone has some sample code for generating 
> a color on a gradient between color a and color b (red and green are 
> traditional but something generic would be nice) based on the value of the 
> variable?
> 
> I guess this is the sort of thing you use for microarray displays/ 
> correlations etc. Cellular automata in this case but it should be useful 
> to others in the list.


This is pretty straightforward in Java, for instance:

      public Color mixColor(Color from, Color to, double amount) {
	  float x = (float) amount;
	  float y = (float) (1.0 - amount);

	  return new Color((int) (y * from.getRed() + x * to.getRed()),
			   (int) (y * from.getGreen() + x * to.getGreen()),
			   (int) (y * from.getBlue() + x * to.getBlue()));
      }

This is nice for 'fluffy' viewing of new data, but for serious
analysis I'd agree with Dan's point about using a discrete scale
instead.

      Thomas.


More information about the Biojava-l mailing list