Graphics, Figures & Tables ⇒ Comparison plot diagram
Comparison plot diagram
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.
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
Comparison plot 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.
Comparison plot diagram
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
Code: Select all
\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
Code: Select all
\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)
};
\addlegendentry{$\rho_3 = \SI{7,82 +- 0,05}{\g/\cm^3}$};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
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: 10324
- Joined: Mon Mar 10, 2008 9:44 pm
Comparison plot diagram
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
Comparison plot diagram
Here's what I got. I think this is it !

Code: Select all
\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]
coordinates {
(7.82, 0) +- (0.04, 0)
};
\addlegendentry{$\rho_3 = \SI{7,82 +- 0,04}{\g/\cm^3}$};
\end{axis}
\end{tikzpicture}
\caption{An example of comparison diagram.}
\end{figure}
\end{document}
Comparison plot diagram
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
\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}$};
\end{axis}
\end{tikzpicture}
\caption{An example of comparison diagram.}
\end{figure}
\end{document}
\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
pgfplotsset
inside the figure environment, that keeps its scope limited.Comparison plot diagram
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.