I have a question about adjusting the number of horizontal tick marks on a 2D plot.


f[x_] := 4*Sin[4*x]

Plot[{f[x]}, {x, -10, 10}, Ticks -> {Table[Pi n, {n, -5, 5}]}]

Gives the following plot:

enter image description here

How would I go about adding more ticks so I could change the range (in terms of $\pi$) to fractional values of $\pi$?

Say $-\pi/10$ to $\pi/10$.

or...in increments of $\pi/2$....or $\pi/4$?

The Plot command I am using is one I found from the help because I couldn't figure out how to make the ticks in terms of $\pi$. I'm still learning some of the basics, but I'm quite stuck on changing the number of ticks.

Anyone have some ideas please?

  • 2
    $\begingroup$ Take a look at Table[Pi n, {n, -5, 5}]. What does it output? What do you need to change to have multiples of Pi/2? $\endgroup$
    – Szabolcs
    Feb 11, 2014 at 17:40
  • $\begingroup$ To be honest I don't know what it does. I thought it merely set the number of labels that show on the 'x-axis', but per your post, which I just did not think of, changing those values to -5/2 and 5/2 gives what I'm looking for. Is there an easier ay to accomplish this however? $\endgroup$
    – fiz
    Feb 11, 2014 at 17:55
  • 3
    $\begingroup$ Then please start by reading up on Table and understanding what it does and how to use it. Use the documentation. Table is one of the most fundamental constructs in Mathematica and it is quite easy to understand. $\endgroup$
    – Szabolcs
    Feb 11, 2014 at 17:58
  • $\begingroup$ Yes, for sure. Up to now it had not come up, but I will look the documentation. Now, your having said that, I asked if there were any other ways to accomplish this task. Is this just one way of doing it, or the easiest? Insight? $\endgroup$
    – fiz
    Feb 11, 2014 at 18:10
  • 1
    $\begingroup$ Yes, it's the easiest. For more complex tick arrangements the CustomTicks package is easier, but not for simple ones like what you described. $\endgroup$
    – Szabolcs
    Feb 11, 2014 at 18:12

1 Answer 1

Plot[4*Sin[4*x], {x, -10, 10}, 
Ticks -> {Table[Pi/2 n, {n, -15, 15}], Automatic}]

enter image description here

  • $\begingroup$ Thank you santosh. I see what you have done. I thought I tried that and got an error, but I like your method. I will look at it again. $\endgroup$
    – fiz
    Feb 11, 2014 at 19:24

Your Answer

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

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