3
$\begingroup$

I am running Mathematica 7. Suppose that I plot $\sin(x)$ for $x = 0..10$ and frame the plot using Frame -> True:

Plot[Sin[x], {x, 0, 10}, PlotRange -> All, Frame -> True]

Plot 1

Now suppose that I would like the horizontal axis to have ticks every $0.5$ (which it does), but with the ticks labeled only every $1$. Is there a way to do this?

FrameTicks seemed to be a possibility, but when I used Range[0, 10, 1] in the bottom horizontal axis specification, I lost the (non-labeled) ticks at every $0.5$:

Plot[Sin[x], {x, 0, 10}, PlotRange -> All, Frame -> True, 
 FrameTicks -> {{Automatic, Automatic}, {Range[0, 10, 1], Automatic}}]

Plot 2

Thanks for your time.

$\endgroup$
  • 2
    $\begingroup$ The CustomTicks package is the way to go, IMHO. $\endgroup$ – Guillochon Jan 14 '13 at 22:34
  • 2
    $\begingroup$ Does FrameTicks -> {{Automatic, Automatic}, {Join[Range[0, 10], Thread[{Range[0.5, 10, 1.], " "}]], Automatic}}] work? $\endgroup$ – kglr Jan 14 '13 at 22:37
  • 1
    $\begingroup$ With the documentation for Frameticks or the results of this search mathematica.stackexchange.com/search?q=frameticks you should have no trouble. $\endgroup$ – DavidC Jan 14 '13 at 22:37
  • $\begingroup$ @kguler Yes, that indeed does work. Thank you! $\endgroup$ – Andrew Jan 14 '13 at 22:46
  • 1
    $\begingroup$ Here's an example of using CustomTicks. I think you'd end up rewriting the same thing anyway. It saves times to just use CustomTicks and you'll get a prettier output with less work. $\endgroup$ – Szabolcs Jan 14 '13 at 23:30
8
$\begingroup$

Using kguler's comment (thank you!), I get the following, which is the output I was looking for:

Plot[Sin[x], {x, 0, 10}, PlotRange -> All, Frame -> True, 
 FrameTicks -> {{Automatic, Automatic}, 
  {Join[Range[0, 10], Thread[{Range[0.5, 10, 1], " "}]], Automatic}}]

Plot 3

$\endgroup$
  • 3
    $\begingroup$ you can control the labels,positions and styling of ticks more finely using the second, third and fourth arguments. Try, for example, Frameticks-> {{Automatic, Automatic}, {Join[{#, #, {.01, 0}} & /@ Range[0, 10], {#, " ", {.0075, 0}, Directive[Red, Thick]} & /@ Range[0.5, 10, 1.]], Automatic}}. (+1) $\endgroup$ – kglr Jan 14 '13 at 22:56

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.