【问题标题】:How can I get the plot label from the name of the plotted list?如何从绘图列表的名称中获取绘图标签?
【发布时间】:2014-01-31 23:46:58
【问题描述】:

我有一个名为DataList 的数据列表。我可以使用ListPlot 绘制数据并在输入列表之后命名该图,如下所示:

ListPlot[DataList, PlotLabel -> ToString[HoldForm[DataList]]]

这行得通,我得到了我想要的情节。但是我有很多数据列表,所以我为此编写了一个函数,使用以下内容:

plot[input_] := ListPlot[input, PlotLabel -> ToString[HoldForm[input]]]

但是,当我现在输入一个列表时,“PlotLabel”不会反映我输入的列表的名称,而是该列表的内容。

有没有办法在函数计算之前提取列表/表达式的名称?

还有什么办法可以规避这个问题?

我非常感谢任何提示。

【问题讨论】:

    标签: plot wolfram-mathematica mathematica-8


    【解决方案1】:
    DataList = {1, 2, 5, 4, 3, 7};
    SetAttributes[plot, HoldFirst];
    plot[input_] := ListPlot[input, PlotLabel -> ToString[Unevaluated[input]]];
    plot[DataList]
    
    ...PlotWithPlotLabel  DataList  snipped...
    

    【讨论】:

    • 由于某种原因,当我在多个数据列表上映射“绘图”功能时它不起作用,如下所示: Map[plot,{DataList01,DataList02,...}] 但是如果我还给 plot “Listable”属性,我至少可以这样做: plot[{DataList01,DataList02,...}]
    • @Stian 那是因为Map 不包含它的第二个参数,所以例如DataList01 将评估。您可以使用Map[plot, Unevaluated @ {DataList01,DataList02,...}] 防止这种情况发生。我鼓励您在专用的Mathematica 网站上提出任何其他问题。
    • Bill,+1,我鼓励你也加入我们Mathematica
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-30
    • 1970-01-01
    • 2012-12-13
    • 1970-01-01
    相关资源
    最近更新 更多