Custom Colors on Mathematica RectangleChart Function

  • Context: Mathematica 
  • Thread starter Thread starter mhmounty
  • Start date Start date
  • Tags Tags
    Function Mathematica
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
4 replies · 5K views
mhmounty
Messages
10
Reaction score
0
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?

-J
 
Physics news on Phys.org
let's say you have an x, y pair like this:

RectangleChart[{...,{x,y},...},...]

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

RectangleChart[{...,Style[{x,y},Red],...},...]

Or alternatively

RectangleChart[{...,{x,y},...},...,ChartStyle->{...,Red,...}]

Where the ChartStyle option was a list with as many elements as your data.
 
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?

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

Map[ColorData["Rainbow"][#]&,a]

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".
 
Thanks so much! The Map function does it perfectly.

-J