# Feed a Manipulate[] Output into a Graphics[]

allTeamsOf5 = Subsets[Range[12], {5}];

rosterRandomAttributes = Table[Table[Round[RandomReal[], .1], {10}], {12}];

rosterRAMean = Mean@rosterRandomAttributes;

rosterRASD = StandardDeviation@rosterRandomAttributes;

allTeamStats = rosterRandomAttributes[[allTeamsOf5[[#]]]] & /@
Range[Length@allTeamsOf5];

allTeamAverageStats = Mean /@ (allTeamStats[[#]]\[Transpose]) & /@ Range[792];

allTeamsDistToMean =
Total[(allTeamAverageStats[[#]] - rosterRAMean)/rosterRASD] & /@ Range[792];

distToMean = (rosterRandomAttributes[[#]] - rosterRAMean) & /@ Range[12];


The below essentially compute the best team we can get out of this roster emphasizing on different attribute through weight. It output a list of 10 value representing the distance to the mean for each.

Manipulate[(Flatten@
allTeamAverageStats[[
Flatten@Position[
Total[{v1, v2, v3, v4, v5, v6, v7, v8, v9, v10}/
Total@{v1, v2, v3, v4, v5, v6, v7, v8, v9, v10} (
allTeamAverageStats[[#]] - rosterRAMean)/rosterRASD] & /@
Range[792],
Max[Total[{v1, v2, v3, v4, v5, v6, v7, v8, v9, v10}/
Total@{v1, v2, v3, v4, v5, v6, v7, v8, v9, v10} (
allTeamAverageStats[[#]] - rosterRAMean)/rosterRASD] & /@
Range[792]]]]]) - rosterRAMean,
{v1, Range[.1, 1, .1]},
{v2, Range[.1, 1, .1]},
{v3, Range[.1, 1, .1]},
{v4, Range[.1, 1, .1]},
{v5, Range[.1, 1, .1]},
{v6, Range[.1, 1, .1]},
{v7, Range[.1, 1, .1]},
{v8, Range[.1, 1, .1]},
{v9, Range[.1, 1, .1]},
{v10, Range[.1, 1, .1]}, ControlType -> Manipulator]


Now I would like the result of that manipulate to feed the below plot : (using solution posted on How can I create a ColorFunction using Blend? )

Show[
Function[attributes,
Graphics[{
Blend[{
{-Max[Abs[distToMean[[1]]]], Red},
{0, LightRed}, {0, LightGreen},
{+Max[Abs[distToMean[[1]]]], Green}},
distToMean[[1]][[attributes]]],
Rectangle[{If[distToMean[[1]][[attributes]] < 0,
distToMean[[1]][[attributes]]*10, 0],
attributes - 1}, {If[distToMean[[1]][[attributes]] < 0, 0,
distToMean[[1]][[attributes]]*10], attributes}],
PlotRange -> {{-6, 6}, {0, 10}}}, AspectRatio -> 16/9,
Epilog -> {Black, Thickness[.05], Line[{{0, 0}, {0, 11}}]}]] /@
Range[10], Frame -> False, FrameTicks -> False]


I would like the output of the manipulate to feed the Graphics instead of distToMean[1] Trying to nest a With[] to avoid repeating the long code, failed for reason I came to understand. I still dont know how I could solve my problem

-

Just Set dist[[1]] to your output inside Manipulate. Putting additionally a Dynamic to your plots let's you see the change live.

(Edit) You can put your graphics of course inside the same Manipulate and change the graphics too. So after evaluating all your definitions from the first code-block, you could do something like

Manipulate[
Column[{
distToMean[[1]] = (Flatten@
allTeamAverageStats[[Flatten@
Position[
Total[{v1, v2, v3, v4, v5, v6, v7, v8, v9, v10}/
Total@{v1, v2, v3, v4, v5, v6, v7, v8, v9,
v10} (allTeamAverageStats[[#]] - rosterRAMean)/
rosterRASD] & /@ Range[792],
Max[Total[{v1, v2, v3, v4, v5, v6, v7, v8, v9, v10}/
Total@{v1, v2, v3, v4, v5, v6, v7, v8, v9,
v10} (allTeamAverageStats[[#]] - rosterRAMean)/
rosterRASD] & /@ Range[792]]]]]) - rosterRAMean,
Show[Function[attributes,
Graphics[{Blend[{{-Max[Abs[distToMean[[1]]]], Red}, {0,
LightRed}, {0, LightGreen}, {+Max[Abs[distToMean[[1]]]],
Green}}, distToMean[[1]][[attributes]]],
Rectangle[{If[distToMean[[1]][[attributes]] < 0,
distToMean[[1]][[attributes]]*10, 0],
attributes - 1}, {If[distToMean[[1]][[attributes]] < 0, 0,
distToMean[[1]][[attributes]]*10], attributes}],
PlotRange -> {{-6, 6}, {0, 10}}}, AspectRatio -> 16/9,
Epilog -> {Black, Thickness[thickness],
Line[{{0, 0}, {0, 11}}]}]] /@ Range[10], Frame -> False,
FrameTicks -> False]
}, Center
],

{v1, Range[.1, 1, .1]}, {v2, Range[.1, 1, .1]}, {v3,
Range[.1, 1, .1]}, {v4, Range[.1, 1, .1]}, {v5,
Range[.1, 1, .1]}, {v6, Range[.1, 1, .1]}, {v7,
Range[.1, 1, .1]}, {v8, Range[.1, 1, .1]}, {v9,
Range[.1, 1, .1]}, {v10, Range[.1, 1, .1]}, {thickness, 0.01, 0.1},
ControlType -> Manipulator]


Note: This is far from being good programming style but for a test it should be fine.

-
No votes? Looks good to me! +1 – Mr.Wizard Feb 4 '12 at 7:03
@Halirutan, I dont know wether my previous comment got deleted. But, again, Thank You. Now what I wanted to do is to manipulate the graphics itself basically Sot have it within the manipulate object. – 500 Feb 6 '12 at 21:02
@500, see the edit in my post. You can of course put it in the same Manipulate and change the graphics there. – halirutan Feb 6 '12 at 21:35
@Halirutan, THank You very much ! – 500 Feb 6 '12 at 21:41