3
$\begingroup$

I would like to remove some ticks from a plot without having to edit manually the list of ticks generated automatically by Mathematica. My aim is to have a plot where the axis label are close to the axis and replace the ticks below them, as in the figure .

I tried with the following couple of functions

extractTicks[plot_] :=  Catch[plot  /. (FrameTicks -> x_) :> (Throw[x]; FrameTicks -> None)]
removeTicks[plot_, ticks_] :=  Show[plot, FrameTicks ->  Map[DeleteCases[#, Alternatives @@ ({_, #} & /@ ticks)] &, extractTicks[plot], {2}]]

These works sometimes but it seems that the way Mathematica handles ticks is not very standardized...

What do you suggest?

$\endgroup$
  • 4
    $\begingroup$ For any sort of reliability, generate your own ticks. The CustomTicks package (part of SciDraw now) makes this easy. If you want to keep using the method you started with, use AbsoluteOptions[yourGraphics, FrameTicks] instead of extractTicks. $\endgroup$ – Szabolcs Feb 22 '15 at 14:03
  • $\begingroup$ In the plot shown in the question there are only 7 ticks. It is, indeed, a fancy task what you formulated, but seems to easier to change ticks by hand by the good old method, is it not? Or you have in mind something very complex? $\endgroup$ – Alexei Boulbitch Feb 23 '15 at 9:40
  • 4
    $\begingroup$ I'm voting to close this question as off-topic because for simple systems it is better to generate ticks manually, whereas SciDraw is much better for systems of any complexity. $\endgroup$ – MarcoB Feb 28 '16 at 5:16
  • $\begingroup$ What you do is going to be quite hard, for often the resulting Graphics object has FrameTicks -> {{Automatic, Automatic},{Automatic, Automatic}} and AbsoluteOptions flips out on that. It is possible by replacing the automatics with True, then running AbsoluteOptions on that and writing a wrapper function that replaces the middle element in the list of ticks with your label, also setting the length of that tick to 0. $\endgroup$ – LLlAMnYP Feb 29 '16 at 10:31

Browse other questions tagged or ask your own question.