Re: question on passing arguments in a function within
- To: mathgroup at smc.vnet.net
- Subject: [mg100533] Re: [mg100487] question on passing arguments in a function within
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Sun, 7 Jun 2009 05:00:59 -0400 (EDT)
- Reply-to: hanlonr at cox.net
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 gmail.com> wrote:
=============
Hello,
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?
Ramiro