Re: Pass argument name to plot label
- To: mathgroup at smc.vnet.net
- Subject: [mg107815] [mg107815] Re: Pass argument name to plot label
- From: Adam <juneappal at gmail.com>
- Date: Sat, 27 Feb 2010 03:13:43 -0500 (EST)
- References: <hm82um$19l$1@smc.vnet.net>
Thanks to the several people who wrote with suggestions. The cleanest, easiest one that does what I want was sent to me by BH: ***METHOD 1: SetAttributes[hplot, HoldFirst] hplot[list_] := Histogram[list, PlotLabel -> Row[{HoldForm[list], ", mean = ", Mean[list]}]] things = {1, 2, 3}; hplot[things] *** That does it, with minimal extra coding. Method 2 comes from DT. I don't understanding scope well enough to understand why this might be a better approach. It does accomplish what I am after, but with a little more overhead: ****METHOD 2 In[13]:= Attributes[hplot]=HoldFirst; hplot[list_]:=Module[{name}, name=StringTake[ToString[Hold[list]], {6,-2}]; Histogram[Evaluate[list],PlotLabel- >Row[{name<>", mean =",Mean[Evaluate[list]]}]]]; mylist={1,2,3,1}; hplot[mylist] **** A third writer, suggested this: *******Method 3 hplot[list_] := Histogram[list, PlotLabel -> Row[{Row[list], ", mean = ", Mean[list]}]] things = {1 , 2, 3}; hplot[things] *** This is appealing because it is even briefer than the first suggestion, but it doesn't do what I am after. It give me as a plot label: - 123, mean = 2 Instead of the desired - things, mean =2 Perhaps it needs only a slight tweak to work, or something is different in our preference files. Thanks again to all three people who sent approaches. -Adam On Feb 26, 1:06 am, Adam <juneap... at gmail.com> wrote: > I have 15 lists with semi-descriptive names. I want to make a > function that builds a plot (histogram, actually) that has the > particular list name as a label. > > Something like this: > > hplot[list_] := > Histogram[list, PlotLabel -> Row[{list, ", mean = ", Mean[list]}= ]] > > When I run it, like so: > things = {1 , 2, 3}; > hplot[things] > > I want the Plot Label to be displayed as: > "things, mean = 2" > > Is this possible? I have tried SymbolName[things], HoldForm[things], > ut either way, my plot label displays as: > {1, 2, 3} , mean = 2