Mathematica Custom Colors on Mathematica RectangleChart Function

AI Thread Summary
The discussion revolves around using the RectangleChart function in Mathematica to color rectangles based on a third variable, z, which is a numerical value scaled between 0 and 1. Initially, the user struggled to apply color using ChartStyle or Style options. A solution was proposed to color individual rectangles by using the Style function with specific color names or by setting ChartStyle with a list of colors. However, the user clarified that their z values were numerical and not color names, prompting a request for a method to convert these numbers into colors. The solution provided involved using the Map function with ColorData to generate a list of RGBColor entries based on the numerical values, allowing for the effective application of color gradients in the chart. The discussion highlights the importance of color schemes in data visualization and offers practical coding solutions for users working with Mathematica.
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
 

Similar threads

Replies
2
Views
3K
Replies
3
Views
2K
Replies
2
Views
2K
Replies
5
Views
5K
Replies
1
Views
7K
Replies
2
Views
4K
Replies
6
Views
8K
Replies
2
Views
3K
Replies
3
Views
9K
Replies
6
Views
14K
Back
Top