Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am looking for the most general possible way to suppress the display of minor ticks in Mathematica plots.1

More specifically, I'm looking for the equivalent (or near-equivalent) of a fictional MinorTicks->None option/setting (and its usual "partial variants", such as MinorTicks->{None, Automatic}, MinorTicks->{Automatic, None}, etc.). This fictional option/setting is one that could be passed to any Mathematica function that accepts a Ticks option, and would have the sole effect of ensuring that the results do not include minor ticks along the element(s) indicated through the options argument (but may still include the usual major ticks, of course).

Note that I don't expect to get, literally, an implementation (somehow) of a MinorTicks option! I'm looking for something equivalent, or nearly so, both in functionality and convenience.

(If this description of the question is clear enough, the remainder of the post may be safely skipped.)


I can imagine at least three possible ways to answer this question. (But there may be other solutions I have not thought about!)

The simplest one, of course, if such an option already existed (e.g. maybe some obscure/undocumented variant of Tick, or some trick with the existing options that would have the net effect of suppressing minor ticks), would be just to post this information. (This is the type of solution that strikes me as most likely, and, as it happens, for me also the most preferable.)

The second one would be if there were some freely downloadable package that implemented a similar functionality.

The third one (which I realize is highly implausible) would be to post, or point me to, a modification of the source code for Mathematica's function for generating ticks (or for a sufficiently close mimic of it) in which all the parts where all the minor-tick-generating code have been disabled. (I realize that this may be too much work; it would suffice, however, just to point me to the source code of the function for producing the default ticks, and that I can use as the starting point for implementing a noMinorTicks function.)


1 Just to be clear, I am interested only in solution that require only "standard" Mathematica (or possibly freely available add-on packages).

share|improve this question
3  
You might be interesting in the CustomTicks package from LevelScheme –  Michael E2 Jul 22 '13 at 14:34
    
@rcollyer I saw the footnote and "The second one" (possible way to answer) in the body. I'm misreading it, or there's a contradiction there. –  Michael E2 Jul 22 '13 at 16:05
    
@MichaelE2 I didn't notice the contradiction. Admonishment redacted. –  rcollyer Jul 22 '13 at 16:07
1  
Since you restated your requirements, LevelScheme` is definitely the way to go. –  rcollyer Jul 22 '13 at 19:36
1  
Presentations also has CustomTicks in which you can specify the number of minor ticks but it does not meet your requirement of freely downloadable. The problem of AbsoluteOptions (in one of the answers) not always reproducing the original ticks can often be solved by also specifying the associated PlotRange in the plot. However, there is also a problem with FrameTicks in that the rule will also eliminate all ticks on the top and right hand side. This could be solved by some extra programming. –  David Park Jul 22 '13 at 19:49

1 Answer 1

up vote 5 down vote accepted

The general form for the tick specification is

{x, label, len, style}

Minor ticks are easily identifiable: they have no label, or more correctly, the label is "". So, we can remove them from the tick specification in the Graphics object directly, if they were present. Unfortunately, in v9, they are often not included, so the internal algorithms take over. You can see this by running

Options[
  Plot[{x, x^2}, {x, 0, 1}],
  Ticks
]
(* Ticks -> Automatic *)

The most straightforward way to acquire the list of ticks, then, is to use AbsoluteOptions, as follows:

Block[{plot = #, ticks}, 
 ticks =  AbsoluteOptions[plot, Ticks] /. 
     {_, "", {_, _}, {_, _}} :> Sequence[];
 plot /. Graphics[g_, opts : OptionsPattern[]] :> 
     Graphics[g, ticks, opts]
] & @ Plot[{x, x^2}, {x, 0, 1}]

enter image description here

Or, as pointed out in the comments, Show simplifies the code quite a bit:

Show[#, 
  AbsoluteOptions[#, Ticks] /. {_, "", {_, _}, {_, _}} :> Sequence[]
]& @ Plot[{x, x^2}, {x, 0, 1}]
share|improve this answer
2  
+1 -- FYI AbsoluteOptions is not always entirely accurate and this may change the ticks relative to the original plot in unanticipated ways. –  Mr.Wizard Jul 22 '13 at 14:36
1  
@Mr.Wizard you are absolutely correct, and I hesitated to post it because of that. But, when it does work, it is the simplest method. I'll probably add something involving FindDivisions later, as it is more robust. Or, you could do it, as you need the points! :) –  rcollyer Jul 22 '13 at 15:59
2  
I'm curious: I would have used Show[plot, ticks] instead of plot /. Graphics... Any significant difference? –  Michael E2 Jul 22 '13 at 16:09
1  
@MichaelE2 no, just habits die hard. I've been working with the raw objects a lot lately, and Show just didn't come to mind. Posted a simpler version. –  rcollyer Jul 22 '13 at 16:56
    
Beware: Formatting your own custom ticks (from FindDivisions) is a headache. Or at least I find handling the cases full of niggling pitfalls - I was going to post something, too, but it's not worth working out the details, given this solution and LevelScheme. –  Michael E2 Jul 22 '13 at 21:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.