# Plotting with arbitrary units

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 ?

• Did you take a look at the extensive help for Plot yet? – 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}]]


gives

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],
Automatic}]]


• Hello, could you make this work with arbitrary units ? Where can I find the extensive help ? Thank you. – joo Apr 10 '15 at 6:54
• @joo: Ever pressed F1 in Mathematica? See Plot and units. – Jinxed Apr 10 '15 at 7:13
• 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. – joo Apr 10 '15 at 7:37
• @joo: Take a look at the option Ticks to Plot in that documentation. I will amdend my answer to that regard shortly. – Jinxed Apr 10 '15 at 7:43
• likewise Ticks -> {{#, StringJoin@ {ToString@#, " a"} } & /@ Range[-2 , 2 ] in case your "unit" is not something Quantity knows – george2079 Apr 10 '15 at 16:34