Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Custom Colors on Mathematica RectangleChart Function

  1. Dec 8, 2009 #1
    I have data in x,y pairs that I am passing to the RectangleChart function in Mathematica. But I want to be able to color each of those rectangles using a third variable z. There seems to be no easy way to do this. I can't get the ChartStyle or Style options to add this color. Anybody know of a good way to do this?

  2. jcsd
  3. Dec 8, 2009 #2


    Staff: Mentor

    let's say you have an x, y pair like this:


    And let's say you wanted it colored Red. Then you would use:


    Or alternatively


    Where the ChartStyle option was a list with as many elements as your data.
  4. Dec 8, 2009 #3
    Thanks for the reply. But I think I was a little bit unclear on my first post. The third value in the list is a number, scaled between 0 and 1. So it's not a color name. And I want to show the intensity of that number with color.

    When I have the list of numbers, scaled 0 to 1, I can't find a way to convert that to a list of colors. GrayLevel[] or Hue[] will not work on a list.

    Anybody else got an idea on how to take a list of numbers, ie., a = {0.5, 0.6, 0.9} and convert that to a list of colors for the ChartStyle option to work?

  5. Dec 9, 2009 #4


    Staff: Mentor

    To convert "a" from a list of numbers into a list of RGBColor entries use:


    If you search in the help for "color schemes" you will find a pretty long list of color gradients that you can use instead of "Rainbow". My favorites are "Rainbow" and "TemperatureMap".
  6. Dec 11, 2009 #5
    Thanks so much! The Map function does it perfectly.

Share this great discussion with others via Reddit, Google+, Twitter, or Facebook