I would like to plot, say, Sin[x/a] with multiples "a" showing on the x axis as units. How can I do that ?

I have tried setting the plot limits e.g. {x, -2a, 2a}. I cannot plot said function even with limits as {x, -2, 2}.

How does one plot functions with parameters ?

  • $\begingroup$ Did you take a look at the extensive help for Plot yet? $\endgroup$ – Jinxed Apr 2 '15 at 11:27

Use the Ticks-option of Plot for this:

Example: a=\[Pi]

With[{a = \[Pi]}, 
 Plot[Sin[x/a], {x, -2 a, 2 a}, 
  Ticks -> {Range[-2 a, 2 a, a], Automatic}]]


new ticks

For "real" quantities, this can be adapted straightforward to display the unit in the ticks:

With[{a = Quantity["Meters"]},
 Plot[Sin[x/a], {x, -2 a, 2 a}, 
  Ticks -> {{QuantityMagnitude@#, #} & /@ Range[-2 a, 2 a, a], 

ticks with units

| improve this answer | |
  • $\begingroup$ Hello, could you make this work with arbitrary units ? Where can I find the extensive help ? Thank you. $\endgroup$ – joo Apr 10 '15 at 6:54
  • $\begingroup$ @joo: Ever pressed F1 in Mathematica? See Plot and units. $\endgroup$ – Jinxed Apr 10 '15 at 7:13
  • $\begingroup$ I regarded that as the regular help. As I found no help with my problem there, I asked here. My question stands - how is it possible to make a plot with "a" showing as the units ? Thanks. $\endgroup$ – joo Apr 10 '15 at 7:37
  • $\begingroup$ @joo: Take a look at the option Ticks to Plot in that documentation. I will amdend my answer to that regard shortly. $\endgroup$ – Jinxed Apr 10 '15 at 7:43
  • $\begingroup$ likewise Ticks -> {{#, StringJoin@ {ToString@#, " a"} } & /@ Range[-2 , 2 ] in case your "unit" is not something Quantity knows $\endgroup$ – george2079 Apr 10 '15 at 16:34

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.