3
$\begingroup$

I have the following list:

l={{46, 1714.29}, {47, 2857.14}, {48, 3714.29}, {49, 5428.57}, {50, 
  8928.57}, {51, 8928.57}, {52, 11571.4}, {53, 14571.4}, {54, 
  17785.7}, {55, 25000.}, {56, 29571.4}, {57, 34214.3}, {58, 
  39214.3}, {59, 44142.9}, {60, 49928.6}, {61, 55714.3}, {62, 
  62214.3}, {63, 69571.4}, {64, 76285.7}, {65, 76285.7}, {66, 
  93571.4}, {67, 104071.}, {68, 114000.}, {69, 121143.}, {70, 
  127786.}, {71, 137214.}, {72, 144929.}, {73, 153143.}, {74, 
  153143.}, {75, 167571.}, {76, 167571.}, {77, 178214.}, {78, 
  183071.}, {79, 186786.}, {80, 188643.}, {81, 191571.}, {82, 
  194786.}, {83, 197214.}, {84, 200214.}, {85, 202500.}, {86, 
  205071.}, {87, 207286.}, {88, 209357.}, {89, 211357.}, {90, 
  213286.}, {91, 214857.}, {92, 216000.}, {93, 217571.}, {94, 
  218286.}, {95, 218714.}, {96, 219643.}}

To find the normal distribution fit I do,

FindFit[l[[All, 2]], 
 a PDF[NormalDistribution[\[Mu], \[Sigma]], x], {a, \[Mu], \[Sigma]},
  x]

Then I plot them using:

Show[ListPlot[l[[All, 2]], PlotStyle -> Red], 
 Plot[9.492714442567708`*^6 PDF[
    NormalDistribution[44.10417734334825`, 17.28548314618452`], 
    x], {x, 0, 200}]]

As you can see they are both starting on 0. This is because I used l[[All, 2]], I wonder how can I move data and the fit to start from x=46 and onwards, to be consistent with x values of list `l`.

$\endgroup$
1
  • $\begingroup$ I'm curious as to the reason for not using the full dataset: sol = FindFit[l, a PDF[NormalDistribution[\[Mu], \[Sigma]], x], {{a, 10^5}, {\[Mu], 40}, {\[Sigma], 20}}, x] followed by Show[ListPlot[l, PlotStyle -> Red], Plot[a PDF[NormalDistribution[\[Mu], \[Sigma]], x] /. sol, {x, 0, 200}]]. $\endgroup$
    – JimB
    Commented Mar 22, 2020 at 5:42

2 Answers 2

4
$\begingroup$
{minx, maxx} = MinMax@l[[All, 1]];
fit = FindFit[l[[All, 2]], a PDF[NormalDistribution[μ, σ], x], {a, μ, σ},   x]; 

Use the option DataRange in ListPlot and shift the argument x in the first argument of Plot by -minx:

Show[ListPlot[l[[All, 2]], PlotStyle -> Red, DataRange -> {minx, maxx}],
  Plot[a PDF[NormalDistribution[μ, σ], x - minx] /. fit, {x, 0, 150}]]

enter image description here

$\endgroup$
1
$\begingroup$

I just solved it, this can be done using:

Show[ListPlot[l], 
 Plot[9.492714442567708`*^6 PDF[
     NormalDistribution[44.10417734334825`, 17.28548314618452`], 
     x], {x, 0, 200}] /. l_Line :> Translate[l, {46, 0}]]
$\endgroup$

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.