MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: question on passing arguments in a function within

As stated in the documentation for ChartElementFunction:

With input data of form {Subscript[d, 1]->Subscript[m, 1],Subscript[d, 2]->Subscript[m, 2],\[Ellipsis]} the metadata associated with Subscript[d, i] is {Subscript[m, i]}

First, you need to modify the definition of g to do something with the metadata

g[{{xmin_, xmax_}, {ymin_, ymax_}}, value_, meta_] :=
 Module[{txt, xmid = (xmax + xmin)/2},
  txt = If[meta == {}, "", meta[[1]]];
  {Polygon[{{xmin, ymin}, {xmax, ymin},
     {xmax, ymax}, {xmin, ymax}}],
   {Thickness[0.005], Black, Line[{{xmid, ymin},
      {(xmin + xmax)/2, ymax}}]},
   Text[Style[txt, 18, Red],
    {xmid, (ymax + ymin)/2}, {-2, 0}]}]

data = {5, 3, 6};

metadata = {"a", "b", "c"};

BarChart[Thread[data -> metadata],
 ChartElementFunction -> g]

Bob Hanlon

---- Ramiro <ramiro.barrantes at> wrote: 


I am trying to use the ChartElementFunction within BarChart to draw
some special error bars.

The following is a step in the right direction and it works:

g[{{xmin_, xmax_}, {ymin_, ymax_}}, values_,
  meta_] := {Polygon[{{xmin, ymin}, {xmax, ymin}, {xmax, ymax}, {xmin,
      ymax}}], {Thickness[0.005], Black,
   Line[{{(xmin + xmax)/2, ymin}, {(xmin + xmax)/2, ymax}}]}}
BarChart[{1, 2, 3}, ChartElementFunction -> g]

I am not sure where g is getting the coordinates from but it does, but
now I would like to include the metadata: the actual values that I
will use for the error bars, however, I am not sure how to pass that
argument (i.e.  ChartElementFunction->g[???] ) .  Any suggestions?


  • Prev by Date: Re: Learning Trace more....
  • Next by Date: Re: interfacing odd usb device to mathematica
  • Previous by thread: Re: Re: mathematica tutor for NYC high school student
  • Next by thread: Re: interfacing odd usb device to mathematica