FindDivisions [] does not work as indicated

FindDivisions [] was added in Mma v7 and seems like a good way to get flexible ticks for charts. See for example this question and its answers.

Usage example:

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

And everything seems right.
But there is a glitch:

 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

As you can see, the red and black ticks overlap each other. It's because

 FindDivisions[{0, 2}, {2, 4}] (* -> {{0, 1, 2}, {{0, 1/4, 1/2, 3/4, 1}, {1, 5/4, 3/2, 7/4, 2}}} *) 

and you can see that the numbers in the first list (main ticks) are repeated in the second list.
However, the FindDivisions [] documentation says:

enter image description here

So, two questions:

  • Is this a mistake, or am I doing (or understanding) something wrong?
  • Any easy way to remove duplicate ticks in a layered structure?
+6
source share
1 answer

This is a bug, possibly in an implementation, although duplicate values ​​can sometimes be useful. (This is certainly useful for building different levels of divisions.)

For ticks, I would probably use code like:

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

to smooth the hierarchy and remove duplicates.


Generalized, for more levels than two:

 divs = Flatten /@ FindDivisions[{0, 2}, {2, 4, 2}]; Complement[#2, #1] & @@@ Partition[divs, 2, 1, -1, {{}}] 
+5
source

Source: https://habr.com/ru/post/890687/


All Articles