dynamic - 数学: dynamic number of menus

标签 dynamic menu wolfram-mathematica plot

我正在尝试在图中创建动态数量的下拉菜单,以绘制各种数量的曲线。 我有previously请求帮助绘制这些数据,效果很好。

第一件事

Needs["PlotLegends`"]

这是一个数据示例(不是实际数字,因为它们太长了)。

data={{year, H, He, Li, C, O, Si, S},
{0, .5, .1, .01, 0.01, 0.01, 0.001, 0.001},
{100, .45, .1, .01, 0.01, 0.01, 0.001, 0.001},
{200, .40, .1, .01, 0.01, 0.01, 0.001, 0.001},
{300, .35, .1, .01, 0.01, 0.01, 0.001, 0.001}}

compounds变量是化合物的数量+1

compounds=8

现在,我的代码是这个

Manipulate[
 ListLogLogPlot[
  {data[[All, {1, i}]],
   data[[All, {1, j}]],
   data[[All, {1, k}]]},
   PlotLegend -> {data[[1, i]],
                 data[[1, j]],
                 data[[1, k]]}
 ],
 {{i, 2, "Compound 1"},Thread[Range[2, compounds] -> Drop[data[[1]], 1]]},
 {{j, 3, "Compound 2"},Thread[Range[2, compounds] -> Drop[data[[1]], 1]]},
 {{k, 4, "Compound 2"},Thread[Range[2, compounds] -> Drop[data[[1]], 1]]},
 ContinuousAction -> False
 ]

Mathematica graphics

正如您所看到的,我可以通过复制 3 行(数据、图例和菜单描述符)中的每一行来轻松添加复合,但它很蹩脚且效率低下。绘制一组大约需要 20 秒,因此这里大约需要 1 分钟(而且我使用了非常高效的集群)。

有没有办法添加一个小菜单或字段,我可以在其中添加要绘制的化合物数量,以便显示正确数量的菜单?我不需要超过 7 个地 block ,但效率......

数字2、4、16是要绘制的默认值。我可以使用默认值(2、14、16 以及我可能选择的其他一些值)创建一个列表,或者它们都可以设置为 2。

谢谢

最佳答案

你可以做这样的事情

Manipulate[
 ListLogLogPlot[data[[All, {1, #}]] & /@ i],
 {{n, 3, "# compounds"}, Range[7], 
  Dynamic[If[Length[i] != n, i = PadRight[{2, 4, 16}, n, 2]];
   PopupMenu[#, Range[7]]] &},
 {{i, {2, 4, 16}}, ControlType -> None},
 Dynamic[Column[
   Labeled[PopupMenu[Dynamic[i[[#]]], 
       Thread[Range[2, compounds] -> Drop[data[[1]], 1]]],
      Row[{"Compound ", #}], Left] & /@ Range[n]]
 ]
]

Mathematica graphics

如果没有 PlotLegend,对于大约 1000x1000 元素的随机数据集来说,它运行得相当快。如果我在 ListLogLogPlot 中包含 PlotLegend 选项,它会减慢很多,因此这可能是您的代码如此缓慢的原因。

关于dynamic - 数学: dynamic number of menus,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8521679/

相关文章:

sql - 如何在 SQL Server 中围绕动态数量的组对值进行分组

Python 动态帮助和自动完成生成

wolfram-mathematica - 数学 : Print Text on 3D-Graphic

geometry - 在 Mathematica 中绘制线性不等式

wolfram-mathematica - TableForm 的 TableHeadings 与左对齐但表格的内容与右对齐

c# - 在 C# 中指定泛型类型参数时如何使用 `dynamic`?

xml - 替换 XML 文件中的动态内容

javascript - 多级点击子菜单

javascript - 单击屏幕或其他按钮时关闭菜单

CSS3 点击菜单