Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

How to use the value of a funtion[label] to assign color to a piece of the pie?

(edited after answer of kguler ) My dude is how to control the colors in ranges of a function of [labels]

In this way I can show: 1.- the percentage of Data(labels), using pieces of pie and 2.- the value f of labels, with range colors (similar to TemperatureMap but customized)

Use a funcion of Data-Labels to control the color os pieces

------ Original Post ------

I want to use a "gradient" or "a reduce (5-6) list of colors"(similar to DarkRainbow with a little colors)?

I was trying with ColorData and ColorDataFunction ( here you can see that I obtain errors with the same code as the reference doc ) but I have no succes!!

percent = {12, 18, 24, 46}
labels = {1, 9, 15, 22}
f = {8, 7, 1, 4}
PieChart[percent, ChartLabels -> labels, ImageSize -> 200, PlotLabel -> "Test-Grad",  ChartStyle -> ColorData["TemperatureMap" {0, 8}]]
PieChart[percent, ChartLabels -> labels, ImageSize -> 200, PlotLabel -> "Test-Comic", ChartStyle -> ColorData[9, "ColorList"]]

In the image you can see any more about explanation: enter image description here

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

Update: I think you after something like

 pc3b = PieChart[percent, ChartLabels -> labels, 
   PlotLabel -> "Test-Grad-3b", ImageSize -> 300,
   ChartStyle -> {ColorData[{"TemperatureMap", {0, 8}}] /@ f}]

enter image description here

Similar trick with ColorFunction should work too...

rule = Thread[percent -> f];
PieChart[percent, ChartLabels -> labels, PlotLabel -> "Test-Grad-4b", 
 ImageSize -> 300,  ColorFunctionScaling -> False,
 ColorFunction -> (ColorData[{"TemperatureMap", {0, 8}}][#1 /. rule] &)]

enter image description here


Original post:

percent = {12, 18, 24, 46};
labels = {1, 9, 15, 22};
f = {8, 7, 1, 4};
pc1 = PieChart[percent, ChartLabels -> labels, PlotLabel -> "Test-Grad-1", 
  ImageSize -> 200, ColorFunction -> "TemperatureMap"];
pc2 = PieChart[percent, ChartLabels -> labels, PlotLabel -> "Test-Grad-2",
  ImageSize -> 200,  ColorFunction -> 
        Function[{angle}, ColorData["TemperatureMap"][angle]]];
(*the following based on guessing how you might want to use color gradients with `f` *)
pc3 = PieChart[percent, ChartLabels -> labels, PlotLabel -> "Test-Grad-3", 
  ImageSize -> 200, ChartStyle -> {ColorData["TemperatureMap"][#] & /@ Rescale[f]}];
pc4 = PieChart[percent, ChartLabels -> labels, PlotLabel -> "Test-Grad-4", 
  ImageSize -> 200, ColorFunction -> Function[{angle},
      ColorData["TemperatureMap"][Nearest[Rescale[f], angle]]]];
pc5 = PieChart[percent, ChartLabels -> labels, PlotLabel -> "Test-Comic", 
  ImageSize -> 200,  ChartStyle -> 9];
Row[{pc1, pc2, pc3, pc4, pc5}, Spacer[5]] // Panel

enter image description here

share|improve this answer
    
Yes I think that´s the good way. f must be a parameter because the color depends on its value. I´m making a image to concrete more. I post in a few minutes –  Mika Ike Apr 21 at 8:29
    
Here are any aditional precisions, sensa.square7.ch/gdfgdfgd10.jpg –  Mika Ike Apr 21 at 8:41
    
Yes :-) , your answer is the cuasi-solution!! It works well and gives similar colors to similar values, and equale colors to equal values of f[label]. But the only detail I would like to control (if possible) is: 1.- define the colors (with CMYK or RGB code) and 2.- the ranges of values of f. –  Mika Ike Apr 21 at 9:24
    
I was seeing that red (how much red, f much high) and warm colors indicate that f is over the mean; and blue(how much blue, much low) and cold colors indicate the lowest values. And I can Reverse colors. If you can show me how to control colors and ranges(as explains in a previous image-link), fantastic; if not, this may be the solution for me, and I´m mark the question solved by you. –  Mika Ike Apr 21 at 9:46
    
@MikaIke, it would be a good idea to avoid questions and answers that keep getting larger/longer :) If the answer is ok for the original version of your question, I suggest you post a new question focusing on the new parts. –  kguler Apr 21 at 10:05
show 2 more comments

E.g.:

PieChart[{10, 20, 40}, ChartLabels -> {"Blah", "blah", "blahhh"}, 
 ImageSize -> 200, PlotLabel -> "Test-Grad", 
 ColorFunction -> ColorData["DarkRainbow"]]

enter image description here

Note there is no color scheme called "gradient" - there is a class of schemes called gradients, you can use ColorData["Gradients"] to see the particular named schemes.

If you want more control over colors assigned, point ColorFunction to your own function that does whatever is needed to the data and returns the appropriate color(s).

share|improve this answer
    
No, The colors depends on the value os a function of the labels. In your example, if F(Blah)=100,F(blahhh)=95,F(blah)=50 . The colors of the piece of Blah has the same (or close/similar) of the piece of blahhhh, because the value of F(Blah) and F(blahhhh) is similar. If you use this colors sensa.square7.ch/hgfhgfg.jpg , Blah and blahh have, the two, a darker color , while the other is ligther. In this way you can show 2 dimensions of data (one with the percent and other with the color.) –  Mika Ike Apr 21 at 7:37
    
@MikaIke as I said, point it to your own color function definition. The above is just showing correct usage of the basic form which you have completely wrong in your example image. Read the documentation, everything needed is there. –  rasher Apr 21 at 7:45
    
I was seeing the documentation (ColorData, colorFunction, and any more) but I can´t understand how to do that question. I continue reading about the issue but Only to put any colors, but in your example how do you put similar colors to "Blah" and "blahhh"(supossing that f[Blah] and f[blahhh] is close)?. using Color functions. –  Mika Ike Apr 21 at 8:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.