Quero traçar a curva em sino para mostrar a distribuição dos dados em torno da média, com um e dois desvios padrão. Possivelmente, comparando dois conjuntos de dados.
Eu tenho o seguinte código de @Stefan Pinnow
% here are your data, just multiplied by 10^9
\begin{filecontents}{data.txt}
2.9954
3.1314
3.1155
3.094
2.8861
3.0875
2.9685
3.0532
2.9003
3.0931
\end{filecontents}
\documentclass[border=2pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{
% use at least this `compat' level so there is no need to prefix
% coordinates with "axis cs:"
compat=1.11,
%
/pgf/declare function={
% `mu' and `sigma' where calculated in Excel using above data
mu=3.03250;
sigma=0.0894182;
% declare gaussian function
gauss(\x)=1/(sigma*sqrt(2*pi))*exp(-((\x-mu)^2)/(2*sigma^2));
% precalculate some values
yA=gauss(mu-2*sigma);
yB=gauss(mu-sigma);
% constant to simply change calculating `domain' and x axis limits
C=2.5;
},
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
% set axis limits and `domain'
xmin=mu-C*sigma,
xmax=mu+C*sigma,
ymin=0,
domain=mu-C*sigma:mu+C*sigma,
% -----------------------------------------------------------------
% nothing changed here
samples=100,
axis lines*=left,
xlabel=$x$,
every axis x label/.style={
at=(current axis.right of origin),
anchor=west,
},
height=5cm,
width=11cm,
xtick=\empty,
ytick=\empty,
axis on top,
hide y axis,
% -----------------------------------------------------------------
% use ticks just at the coordinates of the first `\addplot' ...
xtick=data,
% and show the below labels for these ticks
xticklabels={
$\mu - 2\sigma$,
$\mu - \sigma$,
$\mu$
},
]
% just a dummy plot used for the `xticklabels'
\addplot [draw=none,fill=none] coordinates {
(mu-2*sigma,0)
(mu-sigma,0)
(mu,0)
};
% plot the data point and the corresponding gauss curve
\addplot [only marks,cyan]
table [x index=0,y expr=0] {data.txt};
\addplot [very thick,cyan!50!black] {gauss(x)};
% add some lines and labels
% draw vertical lines
\draw [gray]
(mu-2*sigma,0) -- coordinate (A left) (mu-2*sigma,yA)
(mu+2*sigma,0) -- coordinate (A right) (mu+2*sigma,yA);
\draw [gray]
(mu-sigma,0) -- coordinate (B left) (mu-sigma,yB)
(mu+sigma,0) -- coordinate (B right) (mu+sigma,yB);
% draw labels
\draw [latex-latex]
(A left) -- node [fill=white] {$0.954$} (A right);
\draw [latex-latex]
(B left) -- node [fill=white] {$0.683$} (B right);
\end{axis}
\end{tikzpicture}
\end{document}
O gráfico não se adapta aos meus dados!
meus dados são:
\begin{filecontents}{data.txt}
2.132687
2.634472
2.697368
2.917756
2.582803
2.32906
2.009636
2.483408
1.778771
2.46634
\end{filecontents}
mu=2.403;
sigma=0.327;
Responder1
Acho que agora entendi o seu "problema".
No código da sua pergunta x é fornecidorelativopara μ e σ. E o intervalo y não é especificado, portanto ymax
é escolhido a partir do valor calculado. Mas height
é dado e, portanto, independentemente dos valores escolhidos de μ e σ, a curva parece a mesma. Você veria imediatamente que os valores calculados realmente mudam, se você apenas definir um ymax
valor fixo e depois alterar os valores de μ e σ.
Para provar que plotei ambas as suas curvas em um axis
ambiente com apenas pequenas alterações no código para levar em conta as alterações nos valores de μ e σ.
% used PGFPlots v1.17
% here are your data, just multiplied by 10^9
\begin{filecontents}{data1.txt}
2.9954
3.1314
3.1155
3.094
2.8861
3.0875
2.9685
3.0532
2.9003
3.0931
\end{filecontents}
\begin{filecontents}{data2.txt}
2.132687
2.634472
2.697368
2.917756
2.582803
2.32906
2.009636
2.483408
1.778771
2.46634
\end{filecontents}
\documentclass[border=2pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{
% use at least this `compat' level so there is no need to prefix
% coordinates with "axis cs:"
compat=1.11,
%
/pgf/declare function={
% `mu' and `sigma' where calculated in Excel using above data
mu1=3.03250;
sigma1=0.0894182;
mu2=2.403;
sigma2=0.327;
% declare gaussian function
gauss(\x,\mu,\sigma)=1/(\sigma*sqrt(2*pi))*exp(-((\x-\mu)^2)/(2*\sigma^2));
% precalculate some values
yA1=gauss(mu1-2*sigma1,mu1,sigma1);
yB1=gauss(mu1-sigma1,mu1,sigma1);
% constant to simply change calculating `domain' and x axis limits
C=2.5;
%
xmin=min(mu1-C*sigma1,mu2-C*sigma2);
xmax=max(mu1+C*sigma1,mu2+C*sigma2);
},
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
% set axis limits and `domain'
xmin=xmin,
xmax=xmax,
ymin=0,
% -----------------------------------------------------------------
% nothing changed here
samples=100,
axis lines*=left,
xlabel=$x$,
every axis x label/.style={
at=(current axis.right of origin),
anchor=west,
},
height=5cm,
width=11cm,
xtick=\empty,
ytick=\empty,
axis on top,
hide y axis,
% -----------------------------------------------------------------
% use ticks just at the coordinates of the first `\addplot' ...
xtick=data,
% and show the below labels for these ticks
xticklabels={
$\mu - 2\sigma$,
$\mu - \sigma$,
$\mu$
},
smooth,
]
% just a dummy plot used for the `xticklabels'
\addplot [draw=none,fill=none] coordinates {
(mu1-2*sigma1,0)
(mu1-sigma1,0)
(mu1,0)
};
% plot the data point and the corresponding gauss curve
\addplot [only marks,cyan]
table [x index=0,y expr=0] {data1.txt};
\addplot [very thick,cyan!50!black,domain=mu1-C*sigma1:mu1+C*sigma1]
{gauss(x,mu1,sigma1)};
% plot the data point and the corresponding gauss curve
\addplot [only marks,orange]
table [x index=0,y expr=0] {data2.txt};
\addplot [very thick,orange!75!black,domain=mu2-C*sigma2:mu2+C*sigma2]
{gauss(x,mu2,sigma2)};
% add some lines and labels
% draw vertical lines
\draw [gray]
(mu1-2*sigma1,0) -- coordinate (A left) (mu1-2*sigma1,yA1)
(mu1+2*sigma1,0) -- coordinate (A right) (mu1+2*sigma1,yA1);
\draw [gray]
(mu1-sigma1,0) -- coordinate (B left) (mu1-sigma1,yB1)
(mu1+sigma1,0) -- coordinate (B right) (mu1+sigma1,yB1);
% draw labels
\draw [latex-latex]
(A left) -- node [fill=white] {$0.954$} (A right);
\draw [latex-latex]
(B left) -- node [fill=white] {$0.683$} (B right);
\end{axis}
\end{tikzpicture}
\end{document}
Responder2
De alguma forma, esse código funciona!
% here are your data, just multiplied by 10^9
\begin{filecontents}{data1.txt}
2.132687
2.634472
2.697368
2.917756
2.582803
2.32906
2.009636
2.483408
1.778771
2.46634
\end{filecontents}
\begin{filecontents}{data.txt}
2.065643
2.031713
2.055865
2.365157
2.227517
2.008509
2.790536
2.167367
2.269939
2.065643
\end{filecontents}
\documentclass[border=2pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{
% use at least this `compat' level so there is no need to prefix
% coordinates with "axis cs:"
compat=1.11,
%
/pgf/declare function={
% `mu' and `sigma' where calculated in Excel using above data
mu=2.205;
sigma=0.234;
% declare gaussian function
gauss(\x)=1/(sigma*sqrt(2*pi))*exp(-((\x-mu)^2)/(2*sigma^2));
% precalculate some values
yA=gauss(mu-2*sigma);
yB=gauss(mu-sigma);
% constant to simply change calculating `domain' and x axis limits
C=4
;
},
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
% set axis limits and `domain'
xmin=mu-C*sigma,
xmax=mu+C*sigma,
ymin=0,
domain=mu-C*sigma:mu+C*sigma,
% -----------------------------------------------------------------
% nothing changed here
samples=100,
axis lines*=left,
xlabel=$x$,
every axis x label/.style={
at=(current axis.right of origin),
anchor=west,
},
height=5cm,
width=11cm,
xtick=\empty,
ytick=\empty,
axis on top,
hide y axis,
% -----------------------------------------------------------------
% use ticks just at the coordinates of the first `\addplot' ...
xtick=data,
% and show the below labels for these ticks
xticklabels={
$\mu - 2\sigma$,
$\mu - \sigma$,
$\mu$,
$\mu + \sigma$,
$\mu + 2\sigma$
},
]
% just a dummy plot used for the `xticklabels'
\addplot [draw=none,fill=none] coordinates {
(mu-2*sigma,0)
(mu-sigma,0)
(mu,0)
(mu+sigma,0)
(mu+2*sigma,0)
};
% plot the data point and the corresponding gauss curve
\addplot [only marks,blue]
table [x index=0,y expr=0] {data.txt};
\addplot [very thick,red!50!black] {gauss(x)};
% add some lines and labels
% draw vertical lines
\draw [gray]
(mu-2*sigma,0) -- coordinate (A left) (mu-2*sigma,yA)
(mu+2*sigma,0) -- coordinate (A right) (mu+2*sigma,yA);
\draw [gray]
(mu-sigma,0) -- coordinate (B left) (mu-sigma,yB)
(mu+sigma,0) -- coordinate (B right) (mu+sigma,yB);
% draw labels
\draw [latex-latex]
(A left) -- node [fill=white] {$95 \%$} (A right);
\draw [latex-latex]
(B left) -- node [fill=white] {$68 \%$} (B right);
\end{axis}
\end{tikzpicture}
\end{document}
Atualização 1:
Este código se adapta ao conjunto de dados. Também plotei três gráficos no mesmo gráfico para mostrar as diferenças. No entanto, continua sendo um problema exibir o lendário corretamente. O\muos valores são exibidos como gráfico, portanto o lendário considera isso como gráfico!
% used PGFPlots v1.17
% here are your data, just multiplied by 10^9
% TEE
\begin{filecontents}{data1.txt}
2.132687
2.634472
2.697368
2.917756
2.582803
2.32906
2.009636
2.483408
1.778771
2.46634
\end{filecontents}
% ICE
\begin{filecontents}{data2.txt}
2.065643
2.031713
2.055865
2.365157
2.227517
2.008509
2.790536
2.167367
2.269939
2.065643
\end{filecontents}
% L742
\begin{filecontents}{data3.txt}
1.67097
1.65911
2.96315
2.46577
1.61159
1.46357
1.59512
1.87797
2.37143
1.16881
\end{filecontents}
\documentclass[border=2pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{
% use at least this `compat' level so there is no need to prefix
% coordinates with "axis cs:"
compat=1.11,
%
/pgf/declare function={
% `mu' and `sigma' where calculated in Excel using above data
mu1=2.40;
sigma1=0.33;
mu2=2.2;
sigma2=0.22;
mu3=1.88;
sigma3=0.52;
% declare gaussian function
gauss(\x,\mu,\sigma)=1/(\sigma*sqrt(2*pi))*exp(-((\x-\mu)^2)/(2*\sigma^2));
% precalculate some values
yA1=gauss(mu1-2*sigma1,mu1,sigma1);
yB1=gauss(mu1-sigma1,mu1,sigma1);
yA2=gauss(mu2-2*sigma2,mu2,sigma2);
yB2=gauss(mu2-sigma2,mu2,sigma2);
yA3=gauss(mu3-2*sigma3,mu3,sigma3);
yB3=gauss(mu3-sigma3,mu3,sigma3);
% constant to simply change calculating `domain' and x axis limits
C=2.5;
%
xmin=min(mu1-C*sigma1,mu2-C*sigma2,mu3-C*sigma3);
xmax=max(mu1+C*sigma1,mu2+C*sigma2,mu3+C*sigma3);
},
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
legend pos=north west,
% set axis limits and `domain'
xmin=xmin,
xmax=xmax,
ymin=0,
% -----------------------------------------------------------------
% nothing changed here
samples=100,
axis lines*=left,
xlabel=\tiny{$Error$},
every axis x label/.style={
at=(current axis.right of origin),
anchor=west,
},
height=5cm,
width=11cm,
xtick=\empty,
ytick=\empty,
axis on top,
hide y axis,
% -----------------------------------------------------------------
% use ticks just at the coordinates of the first `\addplot' ...
xtick=data,
% and show the below labels for these ticks
xticklabels={
$\mu_{1}$,
$\mu_{2}$,
$\mu_{3}$
},
smooth,
]
% just a dummy plot used for the `xticklabels'
\addplot [draw=none] coordinates {
(mu1,0)
(mu2,0)
(mu3,0)
};
\addlegendentry[draw = none]{\tiny{$\mu_{1}=2.40$, $\mu_{2}=2.2$, $\mu_{3}=1.88$}}
% plot the data point and the corresponding gauss curve TEE
\addplot [very thick,blue,domain=mu1-C*sigma1:mu1+C*sigma1]
{gauss(x,mu1,sigma1)};
\addlegendentry{\footnotesize{TEE}}
% plot the data point and the corresponding gauss curve ICE
\addplot [very thick,red,domain=mu2-C*sigma2:mu2+C*sigma2]
{gauss(x,mu2,sigma2)};
\addlegendentry{\footnotesize{AcuNav (ICE)}}
% plot the data point and the corresponding gauss curve 742
\addplot [very thick,green,domain=mu3-C*sigma3:mu3+C*sigma3]
{gauss(x,mu3,sigma3)};
\addlegendentry{\footnotesize{L742}}
% add some lines and labels
% draw vertical lines
%TEE
\draw [blue,very thick,fill=blue]
(mu1,0) -- coordinate (A left) (mu1,yA1);
%ICE
\draw [red,very thick,fill=red]
(mu2,0) -- coordinate (A left) (mu2,yA2);
%L742
\draw [fill=green,green,very thick]
(mu3,0) -- coordinate (A left) (mu3,yA3);
% Plot the dots
% TEE
\addplot [only marks,blue]
table [x index=0,y expr=0] {data1.txt};
% ICE
\addplot [only marks,red]
table [x index=0,y expr=0] {data2.txt};
% 742
\addplot [only marks,green]
table [x index=0,y expr=0] {data3.txt};
\end{axis}
\end{tikzpicture}
\end{document}