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 would like to have rounded ticks in my Mathematica plots. They look much better for thick frames

Plot[ {Sin[x], Cos[x]}, {x, 0, 3 Pi}, Frame -> True, FrameStyle -> Directive[Black, Thick]]

gives plot with square tick ends

but I would like to round them, to get something like

plot with round tick ends

There is a function CapForm["Round"] but it is not clear how to use it with plots.

share|improve this question
    

2 Answers 2

up vote 14 down vote accepted

Here is another approach which is based on converting the plot to PDF format first. It makes the tick marks accessible as regular Graphics objects. Specifically, they (and the frame) show up as open JoinedCurve that can be identified by pattern matching. That leads to the following:

p = Plot[{Sin[x], Cos[x]}, {x, 0, 3 Pi}, Frame -> True, 
   FrameStyle -> Directive[Black, Thick]];

First@ImportString[ExportString[p, "PDF"], "PDF"] /. 
 JoinedCurve[{{{0, 2, 0}}}, x_, 
   CurveClosed -> {0}] :> {CapForm["Round"], 
   JoinedCurve[{{{0, 2, 0}}}, x, CurveClosed -> {0}]}

plot

What I did here is to replace the identified curves by wrapping them in {CapForm["Round"], ...}. This will affect all straight lines, including the frame itself (but the frame doesn't have end points because the corners overlap anyway). The plot lines themselves are not affected by the rounding because they aren't straight lines.

The advantage of this approach is that you don't have to manually calculate and specify the tick positions: the ticks will be modified in post-processing without changing their positions. The disadvantage is that the ticks in the resulting plot can no longer be modified by changing the options with Show, because they are "baked in".

share|improve this answer
    
Just wonderful. I'll spend the next hours playing with your answer :) –  eldo Sep 4 at 18:21
    
(+1) Nice! There is built-in FullGraphics function designed exactly for the purpose you achieve (in a hackish way) with Import[Export[...]] but unfortunately its support seems to be dropped since at least version 5. Export to PDF rounds all the coordinates to 16-bit precision and the Imported plot will have lesser accurate positioning of the graphical primitives than the original plot (though it is still sufficient for the most purposes). –  Alexey Popkov Sep 5 at 14:40
    
@AlexeyPopkov Yes, that's right. But FullGraphics was never reliable. And when you're talking about plots with ticks etc., I think we can assume that a reduction to 16-bit precision will be visually imperceptible. This precision issue is indeed important when your goal is to use the vector graphics in some other high-res operation later. Then I don't think one would want a frame and ticks in the first place, though. –  Jens Sep 5 at 16:51

I'm afraid you will have to build your own graphic primitives. Something like this:

Show[
 Plot[Sin[x], {x, 0, 5}],
 Graphics[{GrayLevel[0.3], Table[Disk[{n, 0}, {0.025, 0.04}, {0, Pi}], {n, 0, 5}]}],
 ImageSize -> 600]

enter image description here

share|improve this answer

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.