1
$\begingroup$

Consider the plot

enter image description here

The X-axis presents a log-scale, left-extended from Zero and right-extended to Infinity, with focus on the interval {2,50}. It conveys the information that the functions are 0 at the origin and tend asymptotically to 1.

Q: Is there a way to change the "focused interval" from {2,50} to something else, like {.001,5}?


I would like to draw a plot with logarithmic scale on the X-axis, and linear scale on the Y-axis; the X-axis going to Infinity, while focusing on a specific interval.

Consulting the documentation of Plot/Options/ScalingFunctions, I found out that ScalingFunctions->{"OptA","OptB"} would apply "OptA" scaling to the X-axis and "OptB" to the Y-axis.

Consulting the documentation of ScalingFunctions/Details, I figured the option
{"Infinite",interval}, to

show asymptotic behavior by compressing infinite ranges into finite ranges

by setting an

infinite scale focused on interval

was what I was looking for my X-axis.

I tried

Plot[{F[.25, 0, t], F[.25, .1, t], F[.25, .2, t]}, {t,0, Infinity}, 
  ScalingFunctions -> {{"Infinite", {.001, 50}}, None}, 
  PlotRange -> {0, 1.5}, PlotLegends -> Placed[{"a=0", "a=0.1", "a=0.2"}, {.9, .3}]]

which yielded the output shown in the above image.


Function:

lam[pi2_] := 1/(2 pi2 - 1);
gama[pi2_, a_, t_] := 1 - Exp[lam[pi2]*t] + 2 lam[pi2]^2*t*(pi2 - a)*Exp[lam[pi2]*t];
F[pi2_, a_, t_] := pi2 (1 - pi2)/(pi2 - Exp[lam[pi2]*t] (pi2 - a))/
  (1 - pi2 + Exp[lam[pi2]*t] (pi2 - a))*gama[pi2, a, t]^2
$\endgroup$
2
  • $\begingroup$ There is a syntax error in the definition of F (mismatched parentheses/brackets). Edit your question to correct this. $\endgroup$
    – Bob Hanlon
    Aug 29, 2023 at 15:27
  • $\begingroup$ @BobHanlon Thanks for spotting that. Corrected it. When I copy paste the code from WM to this SE, it introduces extra line breaks, is there a better way to copy paste long lines? Thx $\endgroup$
    – G Frazao
    Aug 29, 2023 at 15:32

2 Answers 2

3
$\begingroup$
$Version

(* "13.3.1 for Mac OS X ARM (64-bit) (July 24, 2023)" *)

Clear["Global`*"]

lam[pi2_] := 1/(2 pi2 - 1);
gama[pi2_, a_, t_] := 
  1 - Exp[lam[pi2]*t] + 2 lam[pi2]^2*t*(pi2 - a)*Exp[lam[pi2]*t];
F[pi2_, a_, t_] := 
 pi2 (1 - pi2)/(pi2 - Exp[lam[pi2]*t] (pi2 - a))/(1 - pi2 + 
     Exp[lam[pi2]*t] (pi2 - a))*gama[pi2, a, t]^2

Using Inset

Plot[Evaluate[F[.25, #, t] & /@ {{0, 0.1, 0.2}}],
 {t, 0, Infinity},
 PlotRange -> {0, 1.5},
 PlotLegends -> Placed[{"a=0", "a=0.1", "a=0.2"}, {.9, .85}],
 Epilog -> Inset[
   LogLinearPlot[Evaluate[F[.25, #, t] & /@ {{0, 0.1, 0.2}}],
    {t, 0.01, 5},
    PlotRange -> {0, 1.5},
    ImageSize -> Medium],
   {.5, .495}],
 ImageSize -> Large,
 Frame -> True]

enter image description here

EDIT: I don't know how to do what you want. However, if your primary interest is the interval {0.001, 5} use either

a = {0, 1/10, 1/5};

funcs = (F[1/4, #, t] & /@ a) // Simplify;

plt = Plot[Evaluate[Tooltip /@ funcs],
  {t, 0, 5},
  PlotRange -> {{0, 5}, {0, 1.5}},
  PlotRangePadding -> Scaled[.05],
  PlotLegends -> Placed[LineLegend[N@a,
     LegendLabel -> Style[HoldForm[a], 14]], {.9, .3}],
  GridLines -> {None, {1}},
  GridLinesStyle -> Directive[AbsoluteThickness[0.75], Gray, Dashed]]

enter image description here

plt = LogLinearPlot[Evaluate[Tooltip /@ funcs],
  {t, 0.001, 5},
  PlotRange -> {0, 1.5},
  PlotRangePadding -> Scaled[.05],
  PlotLegends -> Placed[LineLegend[N@a,
     LegendLabel -> Style[HoldForm[a], 14]], {.9, .3}],
  GridLines -> {None, {1}},
  GridLinesStyle -> Directive[AbsoluteThickness[0.75], Gray, Dashed]]

enter image description here

$\endgroup$
5
  • $\begingroup$ Thanks for your time and answer. Also thanks for the Evaluate[F[.25, #, t] & /@ {{0, 0.1, 0.2}}] trick, it was on my To-look-next list. $\endgroup$
    – G Frazao
    Aug 29, 2023 at 15:59
  • $\begingroup$ The first Plot is already close to what I am looking for: the X-axis presents a log-scale, left-extended from Zero and right-extended to Infinity, with focus on the interval {2,50}. Q: Isn't there a way to change the "focused interval" from {2,50} to something else, like {.001,5}? I am new to WM but I feel it must be doable... $\endgroup$
    – G Frazao
    Aug 29, 2023 at 16:35
  • $\begingroup$ Is plotting to Infinity a new feature in v13? $\endgroup$
    – Syed
    Aug 30, 2023 at 1:05
  • $\begingroup$ @Syed - Yes it is new in v13 $\endgroup$
    – Bob Hanlon
    Aug 30, 2023 at 2:04
  • $\begingroup$ For posterity: Applying the Edit in v13.0.1, the left padding on the X-axis was not working well. A possible workaround is to drop PlotRangePadding and manually pad with PlotRange -> {{.0006, 8}, {0, 1.6}} $\endgroup$
    – G Frazao
    Aug 30, 2023 at 10:37
2
$\begingroup$

You do not need scaling functions for this. For the most common cases there are ready made functions. For your case , you would want: "LogLinearPlot".

Then I do not get the same plot as you. For t->Infiniy the functions -> zero.

Further, if the x axis is logarithmic, it can not start at zero, because this is at infinity.

Here is a plot of your functions from 10^-2 to 5:

M1 = LogLinearPlot[{F[.35, 0, t], F[.25, .1, t], F[.25, .2, t]}, {t, 
   10^-2, 5}, PlotRange -> All, 
  PlotLegends -> Placed[{"a=0", "a=0.1", "a=0.2"}, {.9, .7}]]

enter image description here

$\endgroup$
7
  • $\begingroup$ Thanks for your time and answer. 1) I had an typo in the formula of F (copy pasting introduces line breaks, and I erased a ] in the correction process). 2) I also wanted F[.25, 0, t] in the plot. But these do not affect the essence of the question. $\endgroup$
    – G Frazao
    Aug 29, 2023 at 15:28
  • $\begingroup$ I would like to show the plot from 0.01 to 5, between Zero and Infinity, where is now shown from 2 to 50. Alternatively, is there a way to extend the X-axis in the LogLinearPlot from Zero and to Infinity, similarly to what the plot is doing? I would like to convey that the functions come from 0 and go to 1. $\endgroup$
    – G Frazao
    Aug 29, 2023 at 15:30
  • $\begingroup$ I do not understand: "I would like to show the plot from 0.01 to 5, between Zero and Infinity, where is now shown from 2 to 50". I made you a plot from 0.01 to 5. On a log. axis it is not possible to plot from zero. However, you can plot x->infinity. Your functions are zero at x==0 but go to zero at x->Infinity. Simply change the specification of "t". $\endgroup$ Aug 29, 2023 at 15:53
  • $\begingroup$ I was referring to the Plot in the question. The X-axis presents a log-scale, left-extended from Zero and right-extended to Infinity, with focus on the interval {2,50}. Q: Is there a way to change the "focused interval" from {2,50} to something else, like {.001,5}? $\endgroup$
    – G Frazao
    Aug 29, 2023 at 16:31
  • $\begingroup$ I think I did this in my answer. Note, the original axis from 0 to infinity is NOT a log axis because 0 can not be displayed in a log axis. $\endgroup$ Aug 29, 2023 at 17:11

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.