Mathematica dynamic to plot matrix data

元气小坏坏 提交于 2019-12-05 11:33:45

Mike's suggestion is a good one but if you don't want to go to the effort of putting it in a database, use the ContinuousAction->False option.

testdata = 
  Join[{Table[ToString[series[i-1]], {i, 1475}]}, 
   RandomReal[{1., 100.}, {2000, 1476}]];

Manipulate[
 ListLogLogPlot[testdata[[All, {1, i}]], 
  PlotLabel -> testdata[[1, i]]], {{i, 2, "Compound"}, 2, 1475, 1}, 
 ContinuousAction -> False]

To get a popup menu, use the {i,listofvalues} syntax for the controller specification.

Manipulate[
 ListLogLogPlot[testdata[[All, {1, i}]], 
  PlotLabel -> testdata[[1, i]]], {i, Range[2, 1475]}, 
 ContinuousAction -> False]

This works pretty fast on my system. (Two year old MacBook Pro)

A fancier version:

spec = Thread[Range[2, 1476] -> Table[ToString[series[i]], {i, 1475}]];

Manipulate[
 ListLogLogPlot[testdata[[All, {1, i}]], 
  PlotLabel -> testdata[[1, i]]], {{i, 2, "Compound"}, spec}, 
 ContinuousAction -> False]

And if all you want to do is step through the images, click on the little plus next to a slider controller to get more detailed controls.

For entering names in an InputField, you could do something like

compounds = Rest[data[[1]]];
Manipulate[
 If[MemberQ[compounds, compound], i = Position[compounds, compound][[1, 1]] + 1];
 ListLogLogPlot[data[[All, {1, i}]], PlotLabel -> data[[1, i]]],
 {{i, 2}, None},
 {{compound, data[[1, 2]], "Compound"}, InputField[#, String] &}]

Here, compounds is a list of all the names of the compounds. The If statement in Manipulate is to check whether the name entered in the InputField is a valid compound or not.

Others have already given you ways to create one big popup list. If you don't want to scroll through a popup list of 1475 compounds, you could consider splitting the popup list into sublists. For example, this would split the whole list of compounds into sublists of n=50 elements which might make it easier to navigate

compounds = Rest[data[[1]]];
With[{n = 50},
 Manipulate[
  i = 1 + Position[compounds, name][[1, 1]];
  ListLogLogPlot[data[[All, {1, i}]], PlotLabel -> data[[1, i]]],
  {{i, 2}, None},
  {{indexlist, 1, "Indices"},
   Table[i -> ToString[(i - 1) n + 1] <> " through " <> 
     ToString[Min[i n, Length[compounds]]], 
    {i, Ceiling[Length[compounds]/n]}], PopupMenu},
  {{name, compounds[[1]], "Compound"}, 
   compounds[[n (indexlist - 1) + 1 ;; 
      Min[Length[compounds], n indexlist]]], PopupMenu}
 ]
]

For example, for

data = Table[Join[{i}, RandomReal[{0, 1}, 1000]], {i, 1000}];
data = Join[{Prepend[Table["list " <> ToString[i], {i, 1000}], "year"]}, data];

this looks like

For data sets of this size I'd recommend (as optimal) storing it all in a database and using DatabaseLink to call stuff as required. Then link your controllers, such as popup menus, to SQLExecute code or other SQL functions. Fragments like this would be the sort of thing that would do the job:

DynamicModule[{x,data, ...},

Column[{

PopupMenu[Dynamic[x], {1 -> "category 1", 2 -> "category 2", 3 -> "category 3", ...}],

Dynamic[

data = SQLExecute[conn, "SELECT * FROM myDatabase.table WHERE my_id = `1`;", {x}];
ListLogLogPlot[data]
]

}]
]

In reality you may want to be adding additional popups and doing joins and so on.

EDIT

Alternative that doesn't use databases but uses input fields as requested:

DynamicModule[{x = "He", rules, y},

 rules = Rule @@@ Transpose[{data[[1, All]], Range[Length[data[[1, All]]]]}];

 Column[{
   InputField[Dynamic[x], String],

   Dynamic[
    y = x /. rules;
    ListLogLogPlot[data[[All, {1, y}]], PlotLabel -> data[[1, y]]]
    ]

   }]
 ]

For rules lists of this size you'd probably want to use Dispatch I'd imagine. See how the timing goes for that. It looks like this is some sort of experiment you are running so my first choice remains dumping it into a DB.

FURTHER EDIT

If you're relying on input fields then you will need to account for clumsy typing by inserting a conditional so that Mma only attempts to plot if y is an integer.

If[IntegerQ[y],
ListLogLogPlot,
Spacer[0]
]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!