2
$\begingroup$

I've read this Rescale axes (e.g change from Hz to THz), and tried to change my horizontal of the graph but was failed. I want the $x$-axis is added by $1945$ "Without changing the graph".

For example if my interval is $x\in[0,20]$, then my new interval should be $x\in[1945, 1965]$. And plotting the graph on that interval, i wish the new graph wouldn't change at all. So it's just the numbers that changed.

Here is the picture that might help you to understand my question (sorry for bad drawing).

enter image description here

The step size of the interval should be the same

Here is my attempt:

pp := Plot[123456789 Exp[Log[163123123/123456789]/9 x], {x, -2, 69}, 
   Frame -> True];
fts = FrameTicks /. AbsoluteOptions[pp, FrameTicks];
fts[[1]] = ReplaceAll[#, {tick_, lbl_, {pos_}, {style_}} :> {tick, 
       If[lbl == "", "", ToString[tick + (1945)]], {pos}, {style}}] &@
   fts[[1]];
pp
Plot[123456789 Exp[Log[163123123/123456789]/9 x], {x, -2, 69}, 
 Frame -> True, FrameTicks -> fts]
$\endgroup$

1 Answer 1

3
$\begingroup$

1. You can construct your own ticks using FindDivisions:

fd = FindDivisions[{0, 70}, {7, 6}];

majorticks = Thread[{fd[[1]], 1945 + fd[[1]], {.025, .0}}, List, 2];

minorticks = Thread[{Flatten[Complement[#, First@fd] & /@ Last[fd]], 
    Spacer[0], {.015, 0}}, List, 1];

Plot[123456789 Exp[Log[163123123/123456789]/9 x], {x, -2, 69}, 
 Frame -> True, 
 FrameTicks -> {{Automatic, Automatic}, {Join[majorticks, minorticks], Automatic}}]

enter image description here

2. You can also use Charting`ScaledTicks:

Plot[123456789 Exp[Log[163123123/123456789]/9 x], {x, -2, 69}, 
 Frame -> True, 
 FrameTicks -> {{Automatic, Automatic},
   {Charting`ScaledTicks[{# - 1945 &, # + 1945 &}] &, Automatic}}]

enter image description here

3. Or scale x in the first and second arguments of Plot:

Plot[123456789 Exp[Log[163123123/123456789]/9 (x - 1945)], 
  {x, -2 + 1945, 69 + 1945}, Frame -> True]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thank you so much! $\endgroup$
    – user516076
    Commented Feb 26, 2021 at 14:03

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.