gpt4 book ai didi

wolfram-mathematica - FindDivisions[ ] 未按规定工作

转载 作者:行者123 更新时间:2023-12-04 00:13:00 25 4
gpt4 key购买 nike

FindDivisions[ ]是在 Mma v7 中添加的,似乎是一种为绘图获得灵活刻度的好方法。参见例如 this question及其答案。

用法示例:

f[fd_] := Join[
{#, #, {.07, 0}, Directive[Black, Thickness[.01]]} & /@ fd[[1]],
{#, #, {.05, 0}, Directive[Black, Thin]} & /@ Flatten[fd[[2]]]];
plot[pr_List] :=
Plot[Sin[x], Evaluate@Join[{x}, pr], Ticks -> {f[FindDivisions[pr, {2,5}]]}]

plot[{0, 10}]

enter image description here

一切似乎都是正确的。
但是有一个小故障:
f[fd_] := Join[
{#, #, {.03, 0}, Directive[Red, Thickness[.01]]} & /@ fd[[1]],
{#, #, {.05, 0}, Directive[Black, Thin]} & /@ Flatten[fd[[2]]]];
plot[pr_List] :=
Plot[Sin[x], Evaluate@Join[{x}, pr], Ticks -> {f[FindDivisions[pr, {2,5}]]}]
plot[{0, 10}]

enter image description here

如您所见,红色和黑色刻度叠加在一起。那是因为
FindDivisions[{0, 2}, {2, 4}]
(*
-> {{0, 1, 2}, {{0, 1/4, 1/2, 3/4, 1}, {1, 5/4, 3/2, 7/4, 2}}}
*)

并且您可以看到第一个列表(主要刻度)中的数字在第二个列表中重复。
但是, FindDivisions[] 文档指出:

enter image description here

所以,两个问题:
  • 这是一个错误,还是我在做(或理解)错误?
  • 有什么简单的方法可以删除多级结构中的重复刻度?
  • 最佳答案

    这是一个错误,可能是在实现中,尽管有时具有重复的值可能很有用。 (这对于构建不同级别的划分当然很有用。)

    对于滴答声,我可能会使用如下代码:

    {major, minor} = FindDivisions[{0, 2}, {2, 4}];
    minor = Complement[Flatten[minor], major];

    展平层次结构并删除重复项。

    概括地说,不仅仅是两个级别:
    divs = Flatten /@ FindDivisions[{0, 2}, {2, 4, 2}];
    Complement[#2, #1] & @@@ Partition[divs, 2, 1, -1, {{}}]

    关于wolfram-mathematica - FindDivisions[ ] 未按规定工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6373940/

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