Graphics, Figures & TablesNormal Distribution on Error Bars

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
mayankmi
Posts: 45
Joined: Sat Apr 20, 2013 7:52 pm

Normal Distribution on Error Bars

Post by mayankmi »

This is a bit tough. I tried to draw normal distribution on every error bar. Since in this case the normal distribution has to be inverted. For example 1st normal distribution will be having mean 35 and standard deviation of 7.5. I tried to search so many things but every time they draw y as function of x. I am trying this for two days but could not find it.

Code: Select all

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
  \begin{figure}[!htb]
    \centering
    \begin{tikzpicture}[scale=1],
      \begin{axis}[
        height=8cm,
        width=14cm,  
        xmin=0,
        xmax=4.5,
        ymax=45,
        ymin=20,
        ylabel={Elastic Modulus E (Gpa)},
        axis x line*=bottom,
        axis y line*=left,
        xticklabels={1,2,3,4},xtick={1,...,4},
        x tick label style={anchor=east}
      ]
        \addplot+[black,only marks][error bars/.cd,y dir=both, y explicit] coordinates {
          (4,32.32) +- (0,7.52) 
          (3,32.73) +- (0.0,8.0)
          (2,33.24) +- (0,8.38)
          (1,35) +- (0,7.5)
        };
        \node at (axis cs:4,32.32) [pin={120:(32.32,7.52)},inner sep=0pt] {};
        \node at (axis cs:3,32.73) [pin={130:(32.73,8.0)},inner sep=0pt] {};
        \node at (axis cs:2,33.24) [pin={130:(33.24,8.38)},inner sep=0pt] {};
        \node at (axis cs:1,35) [pin={130:(35,7.5)},inner sep=0pt] {};
        \addplot[color=black] coordinates {(1,35) (2,33.24) (3,32.73) (4,32.32)};
      \end{axis}
    \end{tikzpicture}%
    \caption{Plot showing update for elastic modulus after each data step with trust factor}
    \label{fig:bayesianupdatingstepsincludingt}
  \end{figure}
\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

mayankmi
Posts: 45
Joined: Sat Apr 20, 2013 7:52 pm

Normal Distribution on Error Bars

Post by mayankmi »

I had used this, but it is a super long code and it also compiles very slowly. :cry:

Code: Select all

\documentclass{article}
\usepackage{pgfplots,pgfplotstable}

\usepackage{filecontents}
\begin{filecontents}{dataA.txt}
1.00226226913365    
1.00312239104362    
1.00398127101215    
1.00483763991946    
1.00569020162844    
1.00653763603497    
1.00737860228023    
1.00821174211507    
1.00903568340546    
1.00984904376729    
1.01065043431763    
1.01143846352885    
1.01221174117105    
1.01296888232776    
1.01370851146886    
1.01442926656443    
1.01512980322243    
1.01580879883290    
1.01646495670100    
1.01709701015087    
1.01770372658228    
1.01828391146207    
1.01883641223215    
1.01936012211647    
1.01985398380919    
1.02031699302696    
1.02074820190871    
1.02114672224672    
1.02151172853358    
1.02184246081058    
1.02213822730355    
1.02239840683350    
1.02262245099031    
1.02280988605871    
1.02296031468724    
1.02307341729179    
1.02314895318695    
1.02318676143945    
1.02318676143945    
1.02314895318695    
1.02307341729179    
1.02296031468724    
1.02280988605871    
1.02262245099031    
1.02239840683350    
1.02213822730355    
1.02184246081058    
1.02151172853358    
1.02114672224672    
1.02074820190871    
1.02031699302696    
1.01985398380919    
1.01936012211647    
1.01883641223215    
1.01828391146207    
1.01770372658228    
1.01709701015087    
1.01646495670100    
1.01580879883290    
1.01512980322243    
1.01442926656443    
1.01370851146886    
1.01296888232776    
1.01221174117105    
1.01143846352885    
1.01065043431763    
1.00984904376729    
1.00903568340546    
1.00821174211507    
1.00737860228023    
1.00653763603497    
1.00569020162844    
1.00483763991946    
1.00398127101215    
1.00312239104362    
1.00226226913365
\end{filecontents}

\begin{filecontents}{dataB.txt}
27.5000000000000
27.7000000000000
27.9000000000000    
28.1000000000000    
28.3000000000000    
28.5000000000000    
28.7000000000000    
28.9000000000000
29.1000000000000    
29.3000000000000    
29.5000000000000    
29.7000000000000    
29.9000000000000    
30.1000000000000    
30.3000000000000    
30.5000000000000    
30.7000000000000    
30.9000000000000    
31.1000000000000    
31.3000000000000    
31.5000000000000    
31.7000000000000    
31.9000000000000    
32.1000000000000    
32.3000000000000    
32.5000000000000    
32.7000000000000    
32.9000000000000    
33.1000000000000    
33.3000000000000    
33.5000000000000    
33.7000000000000    
33.9000000000000    
34.1000000000000    
34.3000000000000    
34.5000000000000    
34.7000000000000    
34.9000000000000    
35.1000000000000    
35.3000000000000    
35.5000000000000    
35.7000000000000    
35.9000000000000    
36.1000000000000    
36.3000000000000    
36.5000000000000    
36.7000000000000    
36.9000000000000    
37.1000000000000    
37.3000000000000    
37.5000000000000    
37.7000000000000    
37.9000000000000    
38.1000000000000    
38.3000000000000    
38.5000000000000    
38.7000000000000    
38.9000000000000    
39.1000000000000    
39.3000000000000    
39.5000000000000    
39.7000000000000    
39.9000000000000    
40.1000000000000    
40.3000000000000    
40.5000000000000    
40.7000000000000    
40.9000000000000    
41.1000000000000    
41.3000000000000    
41.5000000000000    
41.7000000000000    
41.9000000000000    
42.1000000000000    
42.3000000000000    
42.5000000000000
\end{filecontents}

\pgfplotstableset{
  create on use/Y/.style={create col/copy column from table={dataB.txt}{0}}
}

\begin{filecontents}{dataC.txt}
1.04332933837174    
1.04562759799475    
1.04790362827434    
1.05013371989158    
1.05229338408093    
1.05435778459123    
1.05630220238241    
1.05810252127097    
1.05973572142331    
1.06118036672514    
1.06241707168585    
1.06342893370566    
1.06420191725237    
1.06472517775032    
1.06499131473688    
1.06499654602633    
1.06474079715211    
1.06422770313069    
1.06346452248881    
1.06246196639620    
1.06123394852609    
1.05979726380824    
1.05817120643961    
1.05637713928919    
1.05443802811000    
1.05237795471225    
1.05022162344257    
1.04799387496574    
1.04571922049369    
1.04342140830877
\end{filecontents}

\begin{filecontents}{dataD.txt}
25.9500000000000    
26.4500000000000    
26.9500000000000    
27.4500000000000    
27.9500000000000    
28.4500000000000    
28.9500000000000    
29.4500000000000    
29.9500000000000    
30.4500000000000    
30.9500000000000    
31.4500000000000    
31.9500000000000    
32.4500000000000    
32.9500000000000    
33.4500000000000    
33.9500000000000    
34.4500000000000    
34.9500000000000    
35.4500000000000    
35.9500000000000    
36.4500000000000    
36.9500000000000    
37.4500000000000    
37.9500000000000    
38.4500000000000    
38.9500000000000    
39.4500000000000    
39.9500000000000    
40.4500000000000
\end{filecontents}

\pgfplotstableset{
    create on use/Y1/.style={create col/copy column from table={dataD.txt}{0}}
}
\begin{filecontents}{dataE.txt}
1.09101228343449    
1.09447941324231    
1.09789444153755    
1.10120261508366    
1.10434757064717    
1.10727288941488    
1.10992375455518    
1.11224864521472    
1.11420099454742    
1.11574073760134    
1.11683567735022    
1.11746260387057    
1.11760811234224    
1.11726907960912    
1.11645277563712    
1.11517660431372    
1.11346748649650    
1.11136091585605    
1.10889973375728    
1.10613268221644    
1.10311280311766    
1.09989575690222    
1.09653813469377    
1.09309583442862
\end{filecontents}

\begin{filecontents}{dataF.txt}
26.8000000000000    
27.3000000000000    
27.8000000000000    
28.3000000000000    
28.8000000000000    
29.3000000000000    
29.8000000000000    
30.3000000000000    
30.8000000000000    
31.3000000000000    
31.8000000000000    
32.3000000000000    
32.8000000000000    
33.3000000000000    
33.8000000000000    
34.3000000000000    
34.8000000000000    
35.3000000000000    
35.8000000000000    
36.3000000000000    
36.8000000000000    
37.3000000000000    
37.8000000000000    
38.3000000000000
\end{filecontents}

\pgfplotstableset{
  create on use/Y2/.style={create col/copy column from table={dataF.txt}{0}}
}

\begin{filecontents}{dataG.txt}
1.15541817620221    
1.16065061163684    
1.16576316055689    
1.17062939066174    
1.17512033658057    
1.17911006861182    
1.18248150393679    
1.18513209029711    
1.18697897894796    
1.18796332345033    
1.18805339327479    
1.18724627241532    
1.18556801616595    
1.18307225430180    
1.17983734512559    
1.17596229105113    
1.17156171262816    
1.16676023650359    
1.16168667923444    
1.15646840212709
\end{filecontents}

\begin{filecontents}{dataH.txt}
27.5000000000000    
28    
28.5000000000000    
29    
29.5000000000000    
30    
30.5000000000000    
31    
31.5000000000000    
32    
32.5000000000000    
33    
33.5000000000000    
34    
34.5000000000000    
35    
35.5000000000000    
36    
36.5000000000000    
37
\end{filecontents}

\pgfplotstableset{
    create on use/Y3/.style={create col/copy column from table={dataH.txt}{0}}
}

\begin{document}
  \begin{figure}[!htb]
    \centering
    \begin{tikzpicture}[scale=1],
      \begin{axis}[
        height=10cm,
        width=15cm,  
        ymax=43,
        ymin=25,
        xmin=.97,
        xmax=1.2,
        ylabel=Elastic Modulus E (Gpa),
        xticklabels={1,2,3,4},xtick={1,1.05,1.1,1.15},
        x tick label
        style={anchor=east}
      ]
        \addplot+[black,only marks][error bars/.cd,y dir=both, y explicit] coordinates {
          (1.15,32.26) +- (0,4.8) 
          (1.085,32.7) +- (0.0,5.89)
          (1.03,33.21) +- (0,7.25)
          (.99,35) +- (0,7.5)
        };
        \node at (axis cs:1.15,32.26) [pin={90:(32.26,4.8)},inner sep=0pt] {};
        \node at (axis cs:1.085,32.7) [pin={90:(32.7,5.89)},inner sep=0pt] {};
        \node at (axis cs:1.03,33.21) [pin={90:(33.21,7.25)},inner sep=0pt] {};
        \node at (axis cs:.99,35) [pin={90:(35,7.5)},inner sep=0pt] {};
        \addplot table [y=Y] {dataA.txt};
        \addplot table [y=Y1] {dataC.txt};
        \addplot table [y=Y2] {dataE.txt};
        \addplot table [y=Y3] {dataG.txt};
      \end{axis}
    \end{tikzpicture}
    \caption{Elastic modulus updating after different steps without trust factor}
    \label{finalfigureE}
  \end{figure}
\end{document}
Post Reply