Graphics, Figures & TablesLabelling 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

Labelling error bars

Post by mayankmi »

The error bars are shown in the figure: is it possible to label them..
for example 7.5 should come for 1st one...etc etc
Also the color of error bars needs to be changed to black.

Code: Select all

\documentclass[12pt]{article}

\usepackage{graphicx}
\usepackage{tikz}
\usepackage{pgfplots}


\begin{document}

\begin{figure}[htbp]
\centering
\begin{tikzpicture}[scale=1],
\centering
\begin{axis}[
height=8cm,
width=14cm,  
  ymax=45,
  ymin=20,
  xmin=0.5,
  xmax=4.5,
  ylabel=Elastic Modulus E (Gpa),
  axis y line*=left,
  axis x line*=bottom,
  xticklabels={Normal Prior-Literature,Normal Posterior-1st update,Normal Posterior-2nd update,Normal Posterior-Final},xtick={1,...,4},
  x tick label style={rotate=90,anchor=east}]
\addplot+[only marks][error bars/.cd,y dir=both, y explicit]
coordinates {
(4,32.26) +- (0,4.8) 
(3,32.7) +- (0.0,5.89)
(2,33.21) +- (0,7.25)
(1,35) +- (0,7.5)
};
\addplot[color=black] coordinates {(1,35) (2,33.21) (3,32.7) (4,32.26)};
\end{axis}
\end{tikzpicture}%
 \caption{Plot showing update after each data step}
    \label{fig:bayesianupdatingstepswithoutt}
\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.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Labelling error bars

Post by Johannes_B »

I would recommend to give the uncertainty in a little table. Plots are for visualisation and comparison of data-points. But you could do something like this. Thorsten is more experienced with tikz and pgfplots than me, he might have a better idea.

Code: Select all

\documentclass{article}
\usepackage{pgfplots}
\begin{document}

\begin{figure}
  \centering
  \begin{tikzpicture}[scale=1],
    \centering
    \begin{axis}[
	height=8cm,
	width=14cm,  
	ymax=45,
	ymin=20,
	xmin=0.5,
	xmax=4.5,
	ylabel=Elastic Modulus E (Gpa),
	xticklabels={Normal
	Prior-Literature,Normal Posterior-1st
	update,Normal Posterior-2nd
	update,Normal
	Posterior-Final},xtick={1,...,4},
	x tick label
	style={rotate=90,anchor=east}]
	\addplot+[black,only marks][error bars/.cd,y dir=both, y explicit]
		      coordinates {
			(4,32.26) +- (0,4.8) 
			(3,32.7) +- (0.0,5.89)
			(2,33.21) +- (0,7.25)
			(1,35) +- (0,7.5)
		      };
\node at (axis cs:4,32.26) [pin={170:4.8},inner sep=0pt] {};
        \node at (axis description cs: 0.16,.5) {7.5};
	\end{axis}
      \end{tikzpicture}%
    \end{figure}
\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
mayankmi
Posts: 45
Joined: Sat Apr 20, 2013 7:52 pm

Re: Labelling error bars

Post by mayankmi »

ya this is ok.. but is it possible to draw normal distribution on these error bars..it has to inverted of course... so like for 4 error bars four normal distribution . i dont know if its too much to ask from latex.. 8-)
Post Reply