I saw a number of related questions to the one I'm about to post; they helped, but none of them solved my problem entirely.
Get the name of a symbol passed to a function
Obtaining the name of a variable as a string
The general question is how to get the name of something (a function, a list...). From the previous questions, I learned that you could use a function with the HoldFirst
attribute:
SetAttributes[f, HoldFirst]
f[x_] := SymbolName[Unevaluated@x]
This function works well when it's input is directly the element of which you want to get the name. However, in my case, I have to use Table[]
and I want to get the name of multiple time series. For example, I have three time series, ts1
, ts2
ts3
. I then want to produce two list plots, both with ts1
on the x axis and then respectively one that has ts2
on the y axis and another that has ts3
on the y axis. Here is the code I used:
Table[
ListPlot[ Transpose[{ts1["Values"],i["Values"]}]
,Frame->True
,FrameLabel->{"ts1",i}
]
,{i,{ts2,ts3}} ]
But the y axis labels, on both plots, are the time series objects, not their names. If I use the function f[_x]
that I linked above, I get:
Table[
ListPlot[ Transpose[{ts1["Values"],i["Values"]}]
,Frame->True
,FrameLabel->{"ts1",f[i]}
]
,{i,{ts2,ts3}} ]
Then the y axis label is just "i"... So what I need is a function that evaluates i
"just enough" (forget the imprecise formulation) so that it is replaced by, let's say, ts2
, but then holds the form and convert it to a symbol. I do not know how to do that.
Here are three time series if you want to try and mess around with them:
ts1={{3686428800,2},{3686515200,2},{3686601600,1},{3686688000,1.4},{3686774400,1.9},{3686860800,1.8},{3687033600,1.7},{3687120000,1.5},{3687206400,2},{3687379200,2},{3687465600,2},{3687552000,2.2},{3687638400,1.7},{3687724800,1.7},{3687897600,1.7},{3687984000,1.7},{3688243200,2},{3688329600,2},{3688502400,1.7},{3688588800,2.3},{3688675200,1.7},{3688761600,1.7},{3688848000,1.7},{3689020800,1.7},{3689107200,2},{3689193600,1.7},{3689366400,2.4},{3689452800,1.7},{3689539200,0.5},{3689625600,2},{3689712000,1.7},{3689798400,1.7},{3689884800,1.7},{3689971200,1.7},{3690057600,2.1},{3690144000,1.7},{3690230400,2.1},{3690316800,3.4}}
ts2={{3686428800,7.7},{3686515200,12.3},{3686601600,9.5},{3686688000,3.7},{3686774400,5.7},{3686860800,5.1},{3687033600,8.3},{3687120000,8.3},{3687206400,6.1},{3687379200,4.3},{3687465600,5.9},{3687552000,5.8},{3687638400,7.5},{3687724800,3.9},{3687897600,5.9},{3687984000,7.6},{3688243200,8.6},{3688329600,4},{3688502400,6.1},{3688588800,5},{3688675200,10},{3688761600,10.6},{3688848000,7.5},{3689020800,7.2},{3689107200,11.3},{3689193600,10.3},{3689366400,9.2},{3689452800,10.2},{3689539200,8},{3689625600,8.3},{3689712000,7.3},{3689798400,7.7},{3689884800,7.9},{3689971200,7.3},{3690057600,9.3},{3690144000,11.9},{3690230400,13},{3690316800,9.8}}
ts3={{3686428800,0.364583},{3686515200,0.395833},{3686601600,0.604167},{3686688000,0.479167},{3686774400,0.458333},{3686860800,0.416667},{3687033600,0.375},{3687120000,0.416667},{3687206400,0.416667},{3687379200,0.40625},{3687465600,0.385417},{3687552000,0.395833},{3687638400,0.375},{3687724800,0.395833},{3687897600,0.416667},{3687984000,0.364583},{3688243200,0.375},{3688329600,0.333333},{3688502400,0.385417},{3688588800,0.375},{3688675200,0.375},{3688761600,0.354167},{3688848000,0.395833},{3689020800,0.416667},{3689107200,0.416667},{3689193600,0.375},{3689366400,0.458333},{3689452800,0.395833},{3689539200,0.395833},{3689625600,0.395833},{3689712000,0.364583},{3689798400,0.385417},{3689884800,0.375},{3689971200,0.354167},{3690057600,0.385417},{3690144000,0.375},{3690230400,0.520833},{3690316800,0.375}}