gpt4 book ai didi

Mathematica 中另一个 Dynamic 中的动态列表选择

转载 作者:行者123 更新时间:2023-12-02 11:59:37 25 4
gpt4 key购买 nike

以贝利撒留在 "Manipulate custom Tabular" 中提出的解决方案为基础.

  • 考虑以下函数来创建自定义表格表示:

    DataSampleXX[data_, linesNumber_, columnsList_, color1_, color2_, color3_] :=

    Grid[
    Join[
    {columnsList}, {Map[Rotate[Text[#], 90 Degree] &,
    data[[1, columnsList]]]}, data[[2 ;; linesNumber, columnsList]]],
    Background -> {{{{color1, color2}}, {1 -> color3}}},
    Dividers -> {All, {1 -> True, 2 -> True, 3 -> True, 0 -> True}},
    ItemSize -> {1 -> Automatic, Automatic},
    Alignment -> Top,
    Frame -> True,
    FrameStyle -> Thickness[2],
    ItemStyle -> {Automatic,
    Automatic, {{1, 1},
    {1, Length[data]}} -> Directive[FontSize -> 15, Black, Bold]}
    ];
  • 以及以下数据:

    soData = {{"col1", "col2", "col3", "col4", "col5", "col6", "col7", 
    "col8", "col9", "col10"}, Range[1, 10], Range[11, 20],
    Range[21, 30], Range[31, 40]}


    With[
    {columnsList = {1, 3},
    data = soData,
    linesNumber = 3,
    color1 = LightBlue,
    color2 = LightRed,
    color3 = LightGray},
    DataSampleXX[data, linesNumber, columnsList, color1, color2, color3]]

Output

  • 我想集成以下动态来提供 DataSampleXX 函数的 columnsList 参数。

    Manipulate[Sort@Join[Sequence @@ {a, b}], 
    Evaluate[Sequence @@ MapThread[{{#1, {}, ""}, #2,
    ControlType -> TogglerBar} &, {{a, b},
    Partition[Rule @@@ Transpose[{Range[10], soData[[1]]}], 5]}]],
    ControlPlacement -> Top]

What I want

  • 这应该使我能够动态选择列(对比我上一个问题中的一系列列)以使用 DataSampleXX 显示,但我还不知道如何合并这两种机制。

最佳答案

你想做的事情需要一些技巧。

例如:

 Maipulate[ f[ Array[ a, exp], ...], ...]

和类似的构造不起作用(并在文档中进行了解释),因为 a[_] 在表达式中并不明确,因此很难拥有可变数量的控件。我找到的解决方案是:

Manipulate[ f[#,...], ... ] & @ Array[a, exp]

另一个问题是构造

 Control@( .#. ) &/@ _controls_ 

本身不允许二维分区,因此我们必须使用两个 Control@ 语法选项(Control@ 和 { ... }),这没有记录。

您可以在下面的代码中找到其他麻烦。

所以:

soData = {{"col01", "col02", "col03", "col04", "col05", "col06", 
"col07", "col08", "col09", "col10"},
Range[1, 10], Range[11, 20], Range[21, 30], Range[31, 40]};
perRow = 5;
colsel = (# -> Graphics[{#, Disk[]}, ImageSize -> 15]) &/@ColorData[1, "ColorList"];
s[x_] := Style[x, Black, Bold, 12];
ct = ControlType -> PopupMenu;

Manipulate[
DataSampleXX[soData, linesNumber, Sort@Join[Sequence @@ #], color1,
color2, color3],
Row[
{Column[
{Control@{{linesNumber, 2, s@"Lines"},
Range[2, Length@soData[[All, 1]] - 1], ct}}],
Spacer[20],
Column[
{Control@{{color1, colsel[[1, 1]], s@"Color 1"}, colsel, ct},
Control@{{color2, colsel[[2, 1]], s@"Color 2"}, colsel, ct},
Control@{{color3, colsel[[3, 1]], s@"Color 3"}, colsel, ct}}]}],
Evaluate[
Sequence @@
MapThread[{{#1, {}, ""}, #2, ControlType -> TogglerBar} &,
{#, Partition[Rule @@@ Transpose[{Range[10], soData[[1]]}], perRow]}]]] &@
Array[a, Length[soData[[1]]]/perRow]

enter image description here

关于Mathematica 中另一个 Dynamic 中的动态列表选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6373919/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com