3
$\begingroup$

While plotting a function I want to change the location of x. I am doing a regression with the logistic function

n = 3998000
modelo = w/(1 + ((w - n)/n)*E^(-q*t))
fit = FindFit[l, modelo, {{w, 9000000}, q}, t]
Show[Plot[modelo /. fit, {t, 0, 2015}], ListPlot[l]]
  • $n$ is the initial population
  • $w$ is the capacity of my logistic function
  • $q$ is the coefficient rate
  • $l$ is my data

l={{1965.,18.5592},{1966.,19.109},{1967.,19.6698},{1968.,20.2349},{1969.,20.7953},{1970.,21.3448},{1971., 21.8802},{1972.,22.4043},{1973.,22.9248},{1974.,23.4527},{1975.,23.9962},{1976.,24.5576},{1977., 25.1346},{1978.,25.7253},{1979.,26.3262},{1980.,26.9346},{1981.,27.5502},{1982.,28.1735},{1983., 28.8033},{1984.,29.438},{1985.,30.0765},{1986.,30.7181},{1987.,31.3625},{1988.,32.009},{1989., 32.6573},{1990.,33.3069},{1991.,33.9573},{1992.,34.6082},{1993.,35.2605},{1994.,35.9154},{1995., 36.5739},{1996.,37.2361},{1997.,37.9014},{1998.,38.5681},{1999.,39.2341},{2000.,39.898},{2001., 40.5586},{2002.,41.2163},{2003.,41.8721},{2004.,42.5276},{2005.,43.184},{2006.,43.8414},{2007., 44.4984},{2008.,45.153},{2009.,45.8026},{2010.,46.4448},{2011.,47.0788},{2012.,47.7044}}.......

The plot is working fine but is taking $t$ as going from 0 to 115 instead of 1900 to 2015. How can I take the function from region [0, 115] to the region [1900, 2015]? I hope I am getting better at asking questions.

$\endgroup$
0
3
$\begingroup$

Both plots are differently scaled, so I propose to use Overlay with two Y-axes

list =
     {{1965., 18.5592}, {1966., 19.109}, {1967., 19.6698}, {1968., 
       20.2349}, {1969., 20.7953}, {1970., 21.3448}, {1971., 
       21.8802}, {1972., 22.4043}, {1973., 22.9248}, {1974., 
       23.4527}, {1975., 23.9962}, {1976., 24.5576}, {1977., 
       25.1346}, {1978., 25.7253}, {1979., 26.3262}, {1980., 
       26.9346}, {1981., 27.5502}, {1982., 28.1735}, {1983., 
       28.8033}, {1984., 29.438}, {1985., 30.0765}, {1986., 
       30.7181}, {1987., 31.3625}, {1988., 32.009}};

n = 3998000;
modelo = w/(1 + ((w - n)/n)*E^(-q*t));
fit = FindFit[list, modelo, {{w, 9000000}, q}, t];

C1 = RGBColor[0.368, 0.507, 0.710];
C2 = RGBColor[0.881, 0.611, 0.142];

p1 =
  ListLinePlot[
   list,
   ImagePadding -> 45,
   ImageSize -> Large,
   Frame -> {True, True, True, False},
   FrameLabel -> "Population",
   FrameStyle -> {Automatic, C1, Automatic, Automatic},
   FrameTicks -> {All, All, None, None},
   GridLines -> Automatic,
   PlotRange -> {{1965, Automatic}, All},
   PlotStyle -> C1];

p2 =
  Plot[
   modelo /. fit, {t, 0, 1},
   Axes -> False,
   ImagePadding -> 45,
   ImageSize -> Large,
   Frame -> {False, False, False, True},
   FrameLabel -> {None, None, None, "Model fit"},
   FrameStyle -> {Automatic, Automatic, Automatic, C2},
   FrameTicks -> {None, None, None, All},
   PlotRange -> Automatic,
   PlotStyle -> C2];

Overlay[{p1, p2}]

enter image description here

$\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.