Plot 两轴绘图,其中一条曲线不完整

Plot 两轴绘图,其中一条曲线不完整,plot,wolfram-mathematica,Plot,Wolfram Mathematica,我使用TwoAxisPlot来组合NDSolve函数的两个绘图,但结果中有一条曲线被截断,因此是不完整的。定义TwoAxisPlot函数时,我不理解所有术语,因此我不知道问题的根源。代码如下: a = 0.99*10^-9; b = 0.24*10^-3; d = 1.21*10^-3; T0 = 1*10^6; n0 = 0.9*10^9; ti = -20; tf = 500; kB = 1.38*10^-16; Qb = 0.33*10^-3; sig = 1; var = sig^2;

我使用TwoAxisPlot来组合NDSolve函数的两个绘图,但结果中有一条曲线被截断,因此是不完整的。定义TwoAxisPlot函数时,我不理解所有术语,因此我不知道问题的根源。代码如下:

a = 0.99*10^-9;
b = 0.24*10^-3;
d = 1.21*10^-3;
T0 = 1*10^6;
n0 = 0.9*10^9;
ti = -20;
tf = 500;
kB = 1.38*10^-16;

Qb = 0.33*10^-3;
sig = 1;
var = sig^2;
Ag = 16.5;

Qg = Ag* Exp[-(t - 10)^2/(2*var)];
Qgt = Qg + Qb;

sss = NDSolve[{T'[t] == -(n[t]^-1) T[t]^(7/2) (a) - 
  n[t] T[t]^(-1/2) (b) + Qgt/(2*kB*n[t]), 
n'[t] == T[t]^(5/2) (a) - (n[t]^2) (T[t]^(-3/2)) (d), T[ti] == T0,
 n[ti] == n0}, {T, n}, {t, ti, tf}];
这给了我两个插值函数,我可以完全单独绘制:

TP = Plot[T[t] /. sss, {t, ti, 300}, PlotRange -> All];
TPPa = Show[TP, Frame -> True, 
FrameLabel -> {{"Temperature, K", ""}, {"Time, s", ""}}]

NP = Plot[n[t] /. sss, {t, ti, 300}, PlotRange -> All];
NPPa = Show[NP, Frame -> True, 
FrameLabel -> {{"Density, \!\(\*SuperscriptBox[\(cm\), \(-3\)]\)", 
 ""}, {"Time, s", ""}}]    

然后,我定义了TwoAxisPlot函数(未更改),该函数复制自此网站:

并使用它

TwoAxisPlot[{T[t] /. sss, n[t] /. sss}, {t, -20, 300}]


但是,绘图现在被截断,并没有显示完整的曲线。如何修复此问题?

添加下面包含的
PlotRange->Full

TwoAxisPlot[{f_, g_}, {x_, x1_, x2_}] := Module[
  {fgraph, ggraph, frange, grange, fticks, gticks},
  {fgraph, ggraph} = MapIndexed[Plot[#, {x, x1, x2}, Axes -> True, 
      PlotStyle -> ColorData[1][#2[[1]]], PlotRange -> Full] &, {f, g}];
  {frange, grange} = (PlotRange /. AbsoluteOptions[#, PlotRange])[[2]] & /@
    {fgraph, ggraph};
  fticks = N@FindDivisions[frange, 5];
  gticks = Quiet@Transpose@{fticks, ToString[NumberForm[#, 2],
          StandardForm] & /@ Rescale[fticks, frange, grange]};
  Show[fgraph, ggraph /. Graphics[graph_, s___] :> Graphics[
      GeometricTransformation[graph, RescalingTransform[{{0, 1}, grange},
        {{0, 1}, frange}]], s], Axes -> False, Frame -> True, 
   FrameStyle -> {ColorData[1] /@ {1, 2}, {Automatic, Automatic}}, 
   FrameTicks -> {{fticks, gticks}, {Automatic, Automatic}}]]

Labeled[
 TwoAxisPlot[{T[t] /. sss, n[t] /. sss}, {t, -20, 300}],
 {Rotate["Temperature, K", Pi/2], "Time, s",
  Rotate["Density, \!\(\*SuperscriptBox[\(cm\), \(-3\)]\)", Pi/2]},
 {Left, Bottom, Right}]

TwoAxisPlot[{f_, g_}, {x_, x1_, x2_}] := Module[
  {fgraph, ggraph, frange, grange, fticks, gticks},
  {fgraph, ggraph} = MapIndexed[Plot[#, {x, x1, x2}, Axes -> True, 
      PlotStyle -> ColorData[1][#2[[1]]], PlotRange -> Full] &, {f, g}];
  {frange, grange} = (PlotRange /. AbsoluteOptions[#, PlotRange])[[2]] & /@
    {fgraph, ggraph};
  fticks = N@FindDivisions[frange, 5];
  gticks = Quiet@Transpose@{fticks, ToString[NumberForm[#, 2],
          StandardForm] & /@ Rescale[fticks, frange, grange]};
  Show[fgraph, ggraph /. Graphics[graph_, s___] :> Graphics[
      GeometricTransformation[graph, RescalingTransform[{{0, 1}, grange},
        {{0, 1}, frange}]], s], Axes -> False, Frame -> True, 
   FrameStyle -> {ColorData[1] /@ {1, 2}, {Automatic, Automatic}}, 
   FrameTicks -> {{fticks, gticks}, {Automatic, Automatic}}]]

Labeled[
 TwoAxisPlot[{T[t] /. sss, n[t] /. sss}, {t, -20, 300}],
 {Rotate["Temperature, K", Pi/2], "Time, s",
  Rotate["Density, \!\(\*SuperscriptBox[\(cm\), \(-3\)]\)", Pi/2]},
 {Left, Bottom, Right}]