4
$\begingroup$

Say I have some plot, such as:

Plot[Exp[-(x - 2)^2/(2*1^2)], {x, 0, 6}, AxesLabel -> {"x", "f(x)"}]   

But I want to present it with the axis labeled as some scalar of a constant amount.

Suppose x represents a physical quantity (e.g. distance) and X=3.1 meters is a fundamental distance in this problem.

How can I change the axes in the plot so that the labels represent the value "x" in terms of "X"?

In other words, I would like for the plot to remain the same, but the previous location of the "1" tick would become ~0.323 (since 0.323*3.1 ~ 1), or a new "1" tick would appear slightly past the original location of the "3" tick.

How can I accomplish this (without changing the plot itself, only the axes representation).

$\endgroup$
  • $\begingroup$ Tick labeling is particularly annoying in Mathematica, which is why I would suggest scaling x in your function instead. So, do Plot[Exp[-(3.1*x - 2)^2/(2*1^2)], {x, 0, 6/3.1}]. $\endgroup$ – march Dec 9 '15 at 22:59
4
$\begingroup$
Plot[
 Exp[-(x - 2)^2/(2*1^2)], {x, 0, 6},
 Ticks -> {Transpose[{#, # .323}] &[Range@6], Automatic},
 AxesLabel -> {"x", "f(x)"}]

enter image description here

$\endgroup$
1
$\begingroup$

I prefer the rescaled plot to show its x-axis ticks with normal Mathematica style divisions rather than have ticks that are multiples of the scale factor. It takes a little more work to do it that way, but I think it is worth the extra effort.

Here is one way it can be done.

f[x_] := Exp[-(x - 2)^2/(2*1^2)]

With[{scaleFactor = .323, xmin = 0, xmax = 6},
  Module[{divisions, xticks},
    divisions = 
      FindDivisions[scaleFactor {xmin, xmax}, {Ceiling[scaleFactor xmax], 5}];
    xticks = Transpose[{# /scaleFactor, #}]&[N[Union @@ divisions[[2]]]];
    Plot[f[x], {x, xmin, xmax},
      PlotRangePadding -> {{Automatic, .2}, Automatic},
      Ticks -> {xticks, Automatic},
      AxesLabel -> {"x", "f(x)"},
      Epilog -> {Red, Line[{{3, 0}, {3, f[3]}}]}]]]

plot

As you can see from the vertical red line, the unscaled value of x = 3 falls very close to the scaled value 1 as expected.

$\endgroup$

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.