21
$\begingroup$

Short version: Is there a value for the FrameTicks option that retains the default tick marks on all sides, and puts tick labels only on the right and top sides?


I can imagine all manner of cleverness with FontOpacity, FontSize, ImagePadding, etc. (for example) to achieve the desired appearance in the example use case below, but, for a number of reasons, in this post I would like to focus on the question as it is worded (under Question heading).


The example below shows what frameticks look like by default.

Graphics[{}, ImageSize -> Small, Frame -> True]

Mathematica graphics

In other words, the default specification for frame ticks can be described in English as:

(default spec)

  1. Tick marks are to be placed on all sides;
  2. Tick labels are to be placed on the left and bottom sides only.

Now, suppose one wants the ticks done according to a small variation of this default spec, one that retains part 1 of the default spec, but changes part 2. For example:

(custom spec)

  1. Tick marks are to be placed on all sides;
  2. Tick labels are to be placed on the right and top sides only.

One approach to achieve this result, of course, is to provide full-blown, explicit tick specifications of the form

{{x1, label1, len1, style1}, …}

...as the values of left, right, bottom, top in

FrameTicks -> {{left, right}, {bottom, top}}

This approach is a pain in the butt, of course, but worse still, it does not come close to matching the generality and maintainability of the default1.


The only other documented possibility is to use some combination of the symbolic settings None, Automatic, True, and/or All.

In search for the "magic combination", I tried the expression

Graphics[{}, ImageSize -> Small, Frame -> True, FrameTicks -> {{a, b}, {a, b}}]

for all possible combinations of values for a and b. (I made a chart of the results for future reference; I've appended it at the end of this post.) The only one that came close to implementing the desired spec was a = None, b = All:

Graphics[{}, ImageSize -> Small, Frame -> True,
         FrameTicks -> {{None, All}, {None, All}}]

Mathematica graphics

This result comes up short because it does not satisfy part 1 of the desired specification.

Bottom line, I have not managed to find a documented setting for FrameTicks that implements the desired spec.


Question

My main question is:

In addition to the one consisting of explicit tick specifications, is there some other (most likely undocumented) value for the FrameTicks option that implements the custom spec above?


Secondarily, I'm also curious to know if there is some documentation that explains why the custom spec above needs to be made so difficult to implement robustly.


P.S. For future reference, in the chart below, the label next to each side gives its FrameTick.

Mathematica graphics

Notes

  1. In all cases, left and bottom have the same setting, and likewise for the settings for right and top.

  2. Along each row, the settings for left and bottom are constant. Along each column, the settings for right and top are constant.

  3. The effect of the True setting (ironically enough) is not universally consistent; it depends on which side it is applied to. On the left and bottom, the effect is "ticks and labels"; on the right and top, it is "ticks only; no labels". (The same could be said of the Automatic setting, but this is reasonable under the interpretation of Automatic as "default".)


1For example, I don't know how I could use this approach in a function that takes some data as input and produces a framed plot that meets the custom tick specification.

$\endgroup$
2
  • 1
    $\begingroup$ I moved your distinguishing statement to the top of the is question as to one degree or another the first three answers posted, mine being one of them, all seem to have ignored it. I deleted my answer which was just an example of ImagePadding. $\endgroup$
    – Mr.Wizard
    Mar 25, 2017 at 14:47
  • 3
    $\begingroup$ @corey979: Mathematica is huge, and its documentation is often incomplete. Knowing that something is not implemented is, in itself, useful information. It saves people a futile search. $\endgroup$
    – kjo
    Mar 25, 2017 at 16:01

3 Answers 3

12
$\begingroup$

Following the strict requirements of your question the nearest solution I can offer is this.

I use the internal tick generating function to behave as All does, but remove the labels.

Edit: I found that what I wrote is already implemented in Charting`ScaledFrameTicks.

magic = Charting`ScaledFrameTicks[{# &, # &}];

Graphics[{}
 , Frame -> True
 , FrameTicks -> {{magic, All}, {magic, All}}
]

enter image description here

$\endgroup$
1
  • $\begingroup$ One weird thing with Charting`ScaledFrameTicks is that many of the ticks disappear, as you can see on the bottom edge of your example. Can this be fixed? $\endgroup$
    – level1807
    Jul 10 at 16:53
8
$\begingroup$

FrameTicks together with FrameTicksStyle do it (as far as I know it's not possible with FrameTicks only:

Graphics[{}, ImageSize -> Small, Frame -> True, FrameTicks -> All, 
 FrameTicksStyle -> {{Directive[FontOpacity -> 0, FontSize -> 0], Automatic},
                     {Directive[FontOpacity -> 0, FontSize -> 0], Automatic}}]

enter image description here

(obtained with $Version: "10.4.1 for Linux x86 (64-bit) (April 11, 2016)").


As pointed out by Szabolcs, in v10.0 (and later) on OSX this does not crop the image, but leaves large borders on the bottom and left. The solution is to change FontSize -> 0 to FontSize -> 0.1.

$\endgroup$
18
  • 1
    $\begingroup$ Thanks. I tried to rule out this solution in my PS, but I guess I was not explicit enough. $\endgroup$
    – kjo
    Mar 25, 2017 at 13:44
  • $\begingroup$ FrameTicks are ticks + labels; ruling out one rules out the other. I very recently was searching for a solution to a similar issue and came up with altering the font options of FrameTicks via FrameTicksStyle. I highly doubt there's a simpler method to achieve this goal (although I would like to find out I'm mistaken). $\endgroup$
    – corey979
    Mar 25, 2017 at 13:49
  • 1
    $\begingroup$ This will not remove the labels: it will leave enough padding for them. But it's good as a quick and dirty solution. $\endgroup$
    – Szabolcs
    Mar 25, 2017 at 13:50
  • $\begingroup$ @Szabolcs Technically it does not remove the labels, but makes them infinitesimally small, cropping the image as much as (by default) possible: imgur.com/a/IB4eE $\endgroup$
    – corey979
    Mar 25, 2017 at 13:57
  • $\begingroup$ @Szabolcs Why the edit? $\endgroup$
    – corey979
    Mar 25, 2017 at 13:58
6
$\begingroup$

With CustomTicks (part of SciDraw, but also usable independently) it's easy to truly remove the tick labels:

Needs["CustomTicks`"]
(* Optional: adjust tick style. Done here so one can better see the ticks *)

linestyle = {AbsoluteThickness[1], Black};

SetOptions[LinTicks, MajorTickLength -> {0.04, 0}, 
  MinorTickLength -> {0.015, 0}, MajorTickStyle -> linestyle, 
  MinorTickStyle -> linestyle];
(* actual plot *)
Graphics[{}, ImageSize -> Small, Frame -> True, 
 FrameTicks -> {StripTickLabels[LinTicks], StripTickLabels[LinTicks], 
   LinTicks, LinTicks}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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