Graphics, Figures & Tables ⇒ Comparison plot diagram
Comparison plot diagram
Suppose you have two (or more) values that you want to compare, one experimental value and one theoretical value (both with their uncertainty). You would want to plot them on the same horizontal axis with their uncertainty, to see if they are compatible (i.e. if they overlap, considering the uncertainty). How could we do that in LaTeX, without importing a picture ?
I searched the internet and the Tikz examples archive and didn't found anything that do this. Any idea about how to achieve a comparison diagram in LaTeX ? Is there any dedicated package for this ?
I searched the internet and the Tikz examples archive and didn't found anything that do this. Any idea about how to achieve a comparison diagram in LaTeX ? Is there any dedicated package for this ?
NEW: TikZ book now 40% off at Amazon.com for a short time.

- Johannes_B
- Site Moderator
- Posts: 4182
- Joined: Thu Nov 01, 2012 4:08 pm
Comparison plot diagram
To be honest, i don't know what you mean with a comparison diagram. If you really have two datapoints, what's the point of a diagram?
There are scatter plots, bar plots, linear plots ... all for different data and their representation.
pgfplots is a dedicated package for plotting data, the website ha many examples.
There are other possibilities, TiKz directly, PSTricks, Asymptote, Metapost, the latter two including importing an image that was first created by a helper program.
There are scatter plots, bar plots, linear plots ... all for different data and their representation.
pgfplots is a dedicated package for plotting data, the website ha many examples.
There are other possibilities, TiKz directly, PSTricks, Asymptote, Metapost, the latter two including importing an image that was first created by a helper program.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Comparison plot diagram
Comparison diagrams are VERY basic, and yet appear to be very uncommon on the internet. I never do these kind of diagrams myself, since they are pretty useless, in a sense. However :
at the scientific institution where I'm teaching physics, we have to ask the students to do a comparison diagram in their laboratory report. They have to graphically show at least two values on a simple horizontal axis (there is no vertical axis in these diagrams). So it's looking like this (crudely done by hand) :
Usually, the students do this with Excel, or in Word.
EDIT : the problem with the packages documention is that they give tons of fancy unrealistic examples but rarely give simple common examples. I'm still unable to understand how to use the pgfplotstable package just to plot a few points on an horizontal axis, without a vertical axis.
at the scientific institution where I'm teaching physics, we have to ask the students to do a comparison diagram in their laboratory report. They have to graphically show at least two values on a simple horizontal axis (there is no vertical axis in these diagrams). So it's looking like this (crudely done by hand) :
Usually, the students do this with Excel, or in Word.
EDIT : the problem with the packages documention is that they give tons of fancy unrealistic examples but rarely give simple common examples. I'm still unable to understand how to use the pgfplotstable package just to plot a few points on an horizontal axis, without a vertical axis.
Comparison plot diagram
Here's a minimal example :
Preview :
It has several issues :
1. The color should be all black. Even the small dots.
2. Each point should have a mathematical label.
3. The vertical axis shouldn't be there.
4. The vertical size should be smaller.
5. The equal sign should be aligned in the legend, without the small dot symbol.
The HUGE documentation isn't clear about how to change these.
Code: Select all
Code, edit and compile here:
\documentclass[10pt,twoside]{revtex4}\usepackage[T1]{fontenc}\usepackage{amsmath}\usepackage{pgfplots}\pgfplotsset{width=7cm}\usepackage[separate-uncertainty=true]{siunitx}\sisetup{output-decimal-marker = {,}}\begin{document}\begin{center}\begin{tikzpicture}\begin{axis}[grid=none,xlabel=$\rho \; (\si{\g/\cm^3})$,yticklabels=none,title={Density comparison},xmin=7.0,xmax=8.0,legend pos=outer north east,]\addplot+[error bars,x dir=both,x explicit]coordinates {(7.90, 0) +- (0.09, 0)};\addlegendentry{$\rho_1 = \SI{7,90 +- 0,09}{\g/\cm^3}$};\addplot+[error bars,x dir=both,x explicit]coordinates {(7.5, 1) +- (0.4, 0)};\addlegendentry{$\rho_2 = \SI{7,5 +- 0,4}{\g/\cm^3}$};\addplot+[error bars,x dir=both,x explicit]coordinates {(7.82, 2) +- (0.05, 0)};\addlegendentry{$\rho_3 = \SI{7,82 +- 0,05}{\g/\cm^3}$};\end{axis}\end{tikzpicture}\end{center}\end{document}
1. The color should be all black. Even the small dots.
2. Each point should have a mathematical label.
3. The vertical axis shouldn't be there.
4. The vertical size should be smaller.
5. The equal sign should be aligned in the legend, without the small dot symbol.
The HUGE documentation isn't clear about how to change these.
Comparison plot diagram
This is *almost* right :
Preview :
However, I still have to change the dot color.
Also, I would prefer to remove the frame around the legend, and center it verticaly to the main diagram. Is this possible ? I didn't found any help in the documentation.
Code: Select all
Code, edit and compile here:
\documentclass[10pt,twoside]{revtex4}\usepackage[T1]{fontenc}\usepackage{amsmath}\usepackage{pgfplots}\pgfplotsset{width=7cm}\usepackage[separate-uncertainty=true]{siunitx}\sisetup{output-decimal-marker = {,}}\begin{document}\begin{center}\begin{tikzpicture}\begin{axis}[scale only axis=true,width=10cm,height=2cm,grid=none,xlabel=$\rho \; (\si{\g/\cm^3})$,ytick=\empty,title={Density comparison},xmin=7.2,xmax=8.0,ymin=-1,ymax=3,legend pos=outer north east,legend style={font=\footnotesize}]\addplot+[color=black,mark=o,mark size=2pt,error bars,x dir=both,x explicit]coordinates {(7.70, 0) +- (0.09, 0)};\addlegendentry{$\rho_1 = \SI{7,70 +- 0,09}{\g/\cm^3}$};\addplot+[color=black,mark=square,mark size=2pt,error bars,x dir=both,x explicit]coordinates {(7.5, 1) +- (0.2, 0)};\addlegendentry{$\rho_2 = \SI{7,5 +- 0,2}{\g/\cm^3}\hphantom{00}$};\addplot+[color=black,mark=*,mark size=2pt,error bars,x dir=both,x explicit]coordinates {(7.82, 2) +- (0.05, 0)};
Also, I would prefer to remove the frame around the legend, and center it verticaly to the main diagram. Is this possible ? I didn't found any help in the documentation.
- Stefan Kottwitz
- Site Admin
- Posts: 10345
- Joined: Mon Mar 10, 2008 9:44 pm
Comparison plot diagram
Hi Cham,
very good minimal example! It's joyful to test it.
You can remove the y axis line by
and you can center the legend at the right side by
bot as options to the axis environment.
I got no quick idea about the colors, but if it's still important I could figure it out.
Stefan
very good minimal example! It's joyful to test it.
You can remove the y axis line by
Code: Select all
axis y line = none
Code: Select all
legend style={at={(1,0.5)}, anchor=west, draw=none}
I got no quick idea about the colors, but if it's still important I could figure it out.
Stefan
LaTeX.org admin
Comparison plot diagram
Thanks Stefan.
Here's what I got. I think this is it !
Preview :
Now, I wonder if the code could be optimized in some way.
Here's what I got. I think this is it !

Code: Select all
Code, edit and compile here:
\documentclass[10pt,twoside,nofootinbib]{revtex4}\usepackage[T1]{fontenc}\usepackage{amsmath}\usepackage{pgfplots}\pgfplotsset{width=7cm}\usepackage[separate-uncertainty=true]{siunitx}\sisetup{output-decimal-marker = {,}}\begin{document}\begin{figure}\centering\begin{tikzpicture}\begin{axis}[scale only axis=true,width=10cm,height=2cm,grid=none,%xtick align=center,xlabel=$\rho \; (\si{\g/\cm^3})$,ytick=\empty,title={Density comparison},xmin=7.2,xmax=8.0,ymin=-1,ymax=3,axis x line = bottom,axis y line = none,legend style={at={(1, 0.5)},anchor=west,font=\footnotesize,draw=none},]\addplot+[color=black,mark options={mark=*,mark size=2pt,fill=black,scale=1},error bars,x dir=both,x explicit]coordinates {(7.5, 2) +- (0.2, 0)};\addlegendentry{$\rho_1 = \SI{7,5 +- 0,2}{\g/\cm^3}\hphantom{00}$};\addplot+[color=black,mark options={mark=square*,mark size=2pt,fill=black,scale=1},error bars,x dir=both,x explicit]coordinates {(7.45, 1) +- (0.09, 0)};\addlegendentry{$\rho_2 = \SI{7,45 +- 0,09}{\g/\cm^3}$};\addplot+[color=black,mark options={mark=triangle*,mark size=2pt,fill=black,scale=1.2},error bars,x dir=both,x explicit]
Comparison plot diagram
Stefan,
in this case, I'm unable to show the secondary ticks, and to make the vertical major grid to be black and dashed. What is wrong in my code ?
I would also like to make the ticks all black, instead of gray.
EDIT : Using
This pgfplots package feels stupid to me. The commands are so non-intuitive and ackward to use. And the documentation is not helping much with all its fancy and complicated examples.
in this case, I'm unable to show the secondary ticks, and to make the vertical major grid to be black and dashed. What is wrong in my code ?
I would also like to make the ticks all black, instead of gray.
Code: Select all
Code, edit and compile here:
\documentclass[10pt,twoside,nofootinbib]{revtex4}\usepackage[T1]{fontenc}\usepackage{amsmath}\usepackage{pgfplots}\pgfplotsset{width=7cm}\usepackage[separate-uncertainty=true]{siunitx}\sisetup{output-decimal-marker = {,}}\begin{document}\begin{figure}\centering\begin{tikzpicture}\begin{axis}[scale only axis=true,width=10cm,height=2.5cm,xlabel=$\rho \, (\si{\g/\cm^3})$,ytick=\empty,title={Density comparison},xmin=7.2,xmax=7.8,ymin=0,ymax=3,xmajorgrids=true,% x tick style={color=black}% major grid style={dashed}minor tick num=1,%xtick align=center,legend style={at={(1.26, 0.5)},anchor=center,font=\footnotesize,draw=none},]\addplot+[color=black,mark options={mark=*,mark size=2pt,fill=black,scale=1},error bars,x dir=both,x explicit]coordinates {(7.5, 2) +- (0.2, 0)};\addlegendentry{$\rho_1 = \SI{7,5 +- 0,2}{\g/\cm^3}\hphantom{00}$};\addplot+[color=black,mark options={mark=square*,mark size=2pt,fill=black,scale=1},error bars,x dir=both,x explicit]coordinates {(7.45, 1) +- (0.09, 0)};\addlegendentry{$\rho_2 = \SI{7,45 +- 0,09}{\g/\cm^3}$};
\pgfplotsset{width=7cm,every tick/.style={black},major grid style={black,dashed}}
in the preamble solves the ticks color and vertical grid rendering. But this is global. It doesn't help if we want to change the rendering locally (for each plot).This pgfplots package feels stupid to me. The commands are so non-intuitive and ackward to use. And the documentation is not helping much with all its fancy and complicated examples.
- Johannes_B
- Site Moderator
- Posts: 4182
- Joined: Thu Nov 01, 2012 4:08 pm
Comparison plot diagram
Use
pgfplotsset
inside the figure environment, that keeps its scope limited.The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Comparison plot diagram
I just tried. It doesn't work (do nothing), whatever where I put it.
EDIT 1 : Hmm, weird. It's working in a small MWE example, but not in my main document.
EDIT 2 : It's working only if I use
I suspect an interaction with some other package.
EDIT 1 : Hmm, weird. It's working in a small MWE example, but not in my main document.
EDIT 2 : It's working only if I use
\pgfplotsset{major grid style={color=black,dotted}}
, instead of \pgfplotsset{major grid style={black,dotted}}
, while the second command line works in the MWE code.I suspect an interaction with some other package.