1
$\begingroup$

I need ticks with equal lenghts to the outside (plen) and to the inside (mlen) of the frame of a plot. I have:

plen=0.0015;
mlen=0.0015;
xTicks = Table[{i, i, {plen, mlen}}, {i, 0, 4, 0.2}];

and I am using Frame -> {{True, False}, {False, True}}, FrameTicks -> {xTicks, Automatic}.

The problem is, the ticks in the resulting image, as seen after exporting to pdf and zoomed in, do not have the same lenght in both directions.

This works if I use Ticks instead, or if the value is changed to 0.003 or above, but I need to use a frame, as I don't know how to force the ticks labels out of the frame by using Ticks, and I need them to be less than 0.003, as I want to distinguish them from other ticks (placed elsewhere) which are about the same lenght.

EDIT: Example code:

Export["amazingplot.pdf", 
 Plot[x^2, {x, 0, 4}, Frame -> {{True, False}, {False, True}}, 
  FrameTicks -> {xTicks, Automatic}, ImageSize -> 1000]]
$\endgroup$
6
  • $\begingroup$ This seems OK in Mathematica 10.1 under Windows. What version/platform are you using? $\endgroup$ – Mr.Wizard Jun 5 '20 at 21:31
  • $\begingroup$ @Mr.Wizard: I am using Mathematica 12 under Windows 10. Meanwhile, I played around a bit and found out that using Union[Table[{i, , {0, 0.0015}}, {i, 0, 4, 0.02}], Table[{i, , {0, -0.0015}}, {i, 0, 4, 0.02}]] (essentially adding out and in ticks separately) seems to work. $\endgroup$ – xihiro Jun 5 '20 at 21:37
  • 1
    $\begingroup$ In MMA 12.0 on Win10-64 I get shorter outward ticks when I use your lengths (which, by the way, is TINY). If I use longer ticks, e.g. plen = mlen = 0.005, then everything seems to work. So, at your size, I can reproduce the problem, but at a longer length it goes away. So it's some awful tricky corner case perhaps in the conversion to PDF. What about other formats (e.g. raster PNG vs. vector SVG)? $\endgroup$ – MarcoB Jun 5 '20 at 21:38
  • $\begingroup$ @MarcoB: I'll try. In the meanwhile, I found a workaround, so I'd say it is not a PDF issue. EDIT: Confirmed, it's not. $\endgroup$ – xihiro Jun 5 '20 at 21:40
  • 1
    $\begingroup$ @xihiro What's the workaround? You might want to put it in a self-answer to this question for others in the future. $\endgroup$ – MarcoB Jun 5 '20 at 21:41
1
$\begingroup$

From the comments, this seems to be a problem with (at least) version 12.0. EDIT: version 12.1 has the same issue.

There's a workaround, by writing a table for the inward ticks and another for the outward ones, only using a negative length:

outxTicks = Table[{i, i, {0,  0.0015}}, {i, 0, 4, 0.02}];
inxTicks  = Table[{i, i, {0, -0.0015}}, {i, 0, 4, 0.02}];
xTicks = Union[outxTicks,inxTicks];
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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