3
$\begingroup$

Please suggest how to rescale the x axis by t0: I am trying to plot given the exponential below.

t0 = .002;
Plot[(1 - Exp[-t/t0]), {t, 0, .008}]
$\endgroup$

2 Answers 2

5
$\begingroup$

Charting`FindTicks

Using the automatically generated scaled ticks:

t0 = .002;
Plot[(1 - Exp[-t/t0]), {t, 0, .008}, PlotRange -> All, 
 Ticks -> {Charting`FindTicks[{0, t0}, {0, 1}], Automatic}]

enter image description here

The function Charting`FindTicks[{a, b}, {c, d}][min, max] generates the major and minor ticks based on the automatically computed minimum and maximum of the values on the axis using the parameters {a, b}, {c, d} for rescaling.

Charting`FindTicks[{0, t0}, {0, 1}][0, .008 ]

{{0., 0}, {0.002, 1}, {0.004, 2}, {0.006, 3}, {0.008, 4},
{0., "", {0.005, 0.}, {Thickness[0.001]}},
{0.0004, "", {0.005, 0.}, {Thickness[0.001]}},
{0.0008, "", {0.005, 0.}, {Thickness[0.001]}},
{0.0012, "", {0.005, 0.}, {Thickness[0.001]}},
{0.0016, "", {0.005, 0.}, {Thickness[0.001]}},
{0.002, "", {0.005, 0.}, {Thickness[0.001]}},
{0.002, "", {0.005, 0.}, {Thickness[0.001]}},
{0.0024, "", {0.005, 0.}, {Thickness[0.001]}},
{0.0028, "", {0.005, 0.}, {Thickness[0.001]}},
{0.0032, "", {0.005, 0.}, {Thickness[0.001]}},
{0.0036, "", {0.005, 0.}, {Thickness[0.001]}},
{0.004, "", {0.005, 0.}, {Thickness[0.001]}},
{0.004, "", {0.005, 0.}, {Thickness[0.001]}},
{0.0044, "", {0.005, 0.}, {Thickness[0.001]}},
{0.0048, "", {0.005, 0.}, {Thickness[0.001]}},
{0.0052, "", {0.005, 0.}, {Thickness[0.001]}},
{0.0056, "", {0.005, 0.}, {Thickness[0.001]}},
{0.006, "", {0.005, 0.}, {Thickness[0.001]}},
{0.006, "", {0.005, 0.}, {Thickness[0.001]}},
{0.0064, "", {0.005, 0.}, {Thickness[0.001]}},
{0.0068, "", {0.005, 0.}, {Thickness[0.001]}},
{0.0072, "", {0.005, 0.}, {Thickness[0.001]}},
{0.0076, "", {0.005, 0.}, {Thickness[0.001]}},
{0.008, "", {0.005, 0.}, {Thickness[0.001]}}}

Another example:

Plot[(1 - Exp[-t/t0]), {t, 0, 5 (.008)}, PlotRange -> All, 
 Ticks -> {Charting`FindTicks[{0, t0}, {0, 1}], Automatic}]

enter image description here

Update 1: How to use it when Frame-> True

Plot[(1 - Exp[-t/t0]), {t, 0, .008}, PlotRange -> All, Frame -> True, 
 FrameTicks -> {{Automatic, Automatic}, {Charting`FindTicks[{0, t0}, {0, 1}], Automatic}}]

enter image description here

Update 2:

Can you suggest about, if I want to find the time constant by taking the log of the plot

Pretending you don't know t0, extract the point coordinates from Plot output and use FindFit or Solve to find the scaling parameter:

plot = Plot[(1 - Exp[-t/t0]), {t, 0, .008}];
coords = Cases[plot, Line[x_] :> x, Infinity][[1]];


a /. FindFit[coords, 1 - Exp[-x/a], {a}, x]

0.002

a /. Quiet @ Solve[(#2 == 1 - Exp[-#/a]), a, Reals][[1]] & @@ coords[[1]]

0.002

$\endgroup$
6
  • $\begingroup$ Thanks@kglr, Does it work for both axis? $\endgroup$ Feb 6, 2018 at 19:58
  • $\begingroup$ @GopalVerma, my pleasure. It does work for all axes. (In 3D too) $\endgroup$
    – kglr
    Feb 6, 2018 at 19:59
  • $\begingroup$ good. Can u suggest about , If I want to find the time constant by taking the log of the plot. $\endgroup$ Feb 6, 2018 at 20:17
  • $\begingroup$ Also, above ticks does not if use Frame-> True. $\endgroup$ Feb 6, 2018 at 20:34
  • $\begingroup$ @GopalVerma, please see the updates. $\endgroup$
    – kglr
    Feb 6, 2018 at 20:50
4
$\begingroup$

I think that you only have to modify your ticks labels:

t0 = .002; 
Plot[(1 - Exp[-t/t0]), {t, 0, .008}, PlotRange -> All, 
Ticks -> {Table[{i, (i/t0)}, {i, 0, 0.008, 0.001}], Automatic}]

enter image description here

$\endgroup$
4
  • $\begingroup$ Thanks@ Navas, It is sufficient. $\endgroup$ Feb 6, 2018 at 19:55
  • $\begingroup$ But, It is not working when I use Frame->True. $\endgroup$ Feb 6, 2018 at 20:22
  • $\begingroup$ Use FrameTicks instead... $\endgroup$ Feb 6, 2018 at 20:24
  • $\begingroup$ yes, It is working. $\endgroup$ Feb 6, 2018 at 20:36

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.