我想对齐下图中两个条形图的聚类。
例如,我希望第二个条形图上的“Program-2”群集出现在第一个条形图的“Program-2”群集的正下方,而第二个条形图上未出现的群集的位置则显示为空(也没有标签)。这可能吗?我该怎么做?
以下是最低限度的示例:
\documentclass{standalone}
\usepackage{tikz,pgfplots}
\usepgfplotslibrary{groupplots}
\usetikzlibrary{calc}
% Define bar chart colors
%
\definecolor{corA}{HTML}{666666}
\definecolor{corB}{HTML}{00FF84}
\definecolor{corC}{HTML}{00994D}
\definecolor{corD}{HTML}{00DD6F}
\pgfplotsset{compat=1.9}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
ybar,
group style = {
group size = 1 by 2,
vertical sep = 5.5cm
},
ymajorgrids = true,
enlarge x limits = 0.03,
ymin = 0,
ymax = 2,
width = 3.00*\textwidth,
height = 8cm,
major x tick style = transparent,
ybar = 2*\pgflinewidth,
xtick=data,
y tick label style= {
font=\Large
},
x tick label style= {
rotate=90,
anchor=east,
font=\Large
},
symbolic x coords = { ,-,
Program-1,
Program-2,
Program-14,
Program-3,
Program-8,
Program-9,
Program-10,
Program-16,
Program-4,
Program-5,
Program-15,
Program-6,
Program-7,
Program-13,
Program-11,
Program-12,
},
legend cell align = left,
legend columns = 4,
legend image code/.code={%
\draw[#1] (-0.1cm,-0.1cm) rectangle (0.10cm,0.2cm);
},
legend style = {
at={(0.800, 2.80)},
anchor=north,
column sep=1ex
}
]
% First Part First Part First Part First Part First Part First Part
% First Part First Part First Part First Part First Part First Part
% First Part First Part First Part First Part First Part First Part
% First Part First Part First Part First Part First Part First Part
% First Part First Part First Part First Part First Part First Part
% First Part First Part First Part First Part First Part First Part
\nextgroupplot[ylabel style={font=\huge}, ylabel={Results of xyz}]
%%%%%%%%%%%%%%%%%%%%%%
%%%% Resultados do A
\addplot[style={corA, fill=corA, mark=none}]
coordinates {
(Program-1, 1.03)
(Program-2, 1.60)
(Program-14, 1.00)
(Program-3, 2.00)
(Program-16, 0.91)
(Program-4, 0.91)
(Program-5, 1.00)
(Program-15, 1.41)
(Program-6, 1.60)
(Program-7, 1.55)
(Program-8, 1.02)
(Program-9, 1.00)
(Program-10, 1.00)
(Program-13, 1.05)
(Program-11, 1.23)
(Program-12, 1.78)
};
%%%%%%%%%%%%%%%%%%%%%%
%%%% Resultados do B
\addplot[style={corB,fill=corB,mark=none}]
coordinates {
(Program-1, 0.92)
(Program-2, 1.60)
(Program-14, 1.08)
(Program-3, 1.00)
(Program-16, 0.18)
(Program-4, 0.20)
(Program-5, 0.26)
(Program-15, 0.89)
(Program-6, 0.52)
(Program-7, 0.39)
(Program-8, 1.02)
(Program-9, 1.00)
(Program-10, 1.00)
(Program-13, 0.62)
(Program-11, 0.66)
(Program-12, 0.71)
};
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Resultados do C
\addplot [style={corC,fill=corC,mark=none}]
coordinates {
(Program-1, 1.03)
(Program-2, 1.60)
(Program-14, 1.00)
(Program-3, 2.00)
(Program-16, 0.07)
(Program-4, 0.09)
(Program-5, 0.38)
(Program-15, 0.49)
(Program-6, 0.73)
(Program-7, 0.52)
(Program-8, 1.02)
(Program-9, 1.00)
(Program-10, 1.00)
(Program-13, 0.14)
(Program-11, 0.16)
(Program-12, 0.21)
};
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Resultados do C Unrolled
\addplot [style={corD,fill=corD,mark=none}]
coordinates {
(Program-1, 1.03)
(Program-2, 1.60)
(Program-14, 1.00)
(Program-3, 2.00)
(Program-16, 0.40)
(Program-4, 0.46)
(Program-5, 0.83)
(Program-15, 1.42)
(Program-6, 1.45)
(Program-7, 1.55)
(Program-8, 1.02)
(Program-9, 1.00)
(Program-10, 1.02)
(Program-13, 0.72)
(Program-11, 0.97)
(Program-12, 1.39)
};
% Second Part Second Part Second Part Second Part Second Part Second Part
% Second Part Second Part Second Part Second Part Second Part Second Part
% Second Part Second Part Second Part Second Part Second Part Second Part
% Second Part Second Part Second Part Second Part Second Part Second Part
% Second Part Second Part Second Part Second Part Second Part Second Part
% Second Part Second Part Second Part Second Part Second Part Second Part
% Second Part Second Part Second Part Second Part Second Part Second Part
% Second Part Second Part Second Part Second Part Second Part Second Part
% Second Part Second Part Second Part Second Part Second Part Second Part
% Second Part Second Part Second Part Second Part Second Part Second Part
\nextgroupplot[ylabel style={font=\huge}, ylabel={Results of ijk}]
%%%%%%%%%%%%%%%%%%%%%%
%%%% Resultados do A
\addplot[style={corA, fill=corA, mark=none}, x tick style={blue}]
coordinates {
(Program-1, 0.00)
(Program-2, 1.46)
(Program-3, 1.04)
(Program-4, 1.15)
(Program-5, 0.88)
(Program-6, 0.95)
(Program-7, 1.41)
(Program-8, 1.07)
(Program-9, 1.04)
(Program-10, 1.00)
(Program-11, 1.30)
(Program-12, 1.38)
};
%%%%%%%%%%%%%%%%%%%%%%
%%%% Resultados do B
\addplot[style={corB,fill=corB,mark=none}]
coordinates {
(Program-2, 1.49)
(Program-3, 1.05)
(Program-4, 0.85)
(Program-5, 0.83)
(Program-6, 0.87)
(Program-7, 1.09)
(Program-8, 1.06)
(Program-9, 1.01)
(Program-10, 0.99)
(Program-11, 0.69)
(Program-12, 0.69)
};
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Resultados do C
\addplot [style={corC,fill=corC,mark=none}]
coordinates {
(Program-2, 1.34)
(Program-3, 1.04)
(Program-4, 0.46)
(Program-5, 0.60)
(Program-6, 0.95)
(Program-7, 1.41)
(Program-8, 1.03)
(Program-9, 0.96)
(Program-10, 0.98)
(Program-11, 0.52)
(Program-12, 0.56)
};
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Resultados do C Unrolled
\addplot [style={corD,fill=corD,mark=none}]
coordinates {
(Program-2, 1.34)
(Program-3, 1.04)
(Program-4, 0.85)
(Program-5, 0.83)
(Program-6, 0.95)
(Program-7, 1.41)
(Program-8, 1.04)
(Program-9, 1.04)
(Program-10, 1.00)
(Program-11, 0.88)
(Program-12, 0.95)
};
\legend{A, B, C, D}
\end{groupplot}
\end{tikzpicture}
\end{document}
答案1
为了达到预期的结果,您只需更改代码中的两行。
- 添加
xmin={[normalized]2]}
到第二个选项\nextgroupplot
([normalize]
因为您正在使用,所以需要symbolic x coords
)并 - 删除或者注释掉第二个
(Program-1,0.00)
中第一行。\addplot
\nextgroupplot
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
% Define bar chart colors
\definecolor{corA}{HTML}{666666}
\definecolor{corB}{HTML}{00FF84}
\definecolor{corC}{HTML}{00994D}
\definecolor{corD}{HTML}{00DD6F}
\pgfplotsset{compat=1.3}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
ybar,
group style = {
group size = 1 by 2,
vertical sep = 3.5cm
},
ymajorgrids = true,
enlarge x limits = 0.03,
ymin = 0,
ymax = 2,
width = 3.00*\textwidth,
height = 8cm,
ybar = 2*\pgflinewidth,
xtick=data,
y tick label style= {
font=\Large
},
x tick label style= {
rotate=90,
anchor=east,
font=\Large
},
symbolic x coords = { ,-,
Program-1,
Program-2,
Program-14,
Program-3,
Program-8,
Program-9,
Program-10,
Program-16,
Program-4,
Program-5,
Program-15,
Program-6,
Program-7,
Program-13,
Program-11,
Program-12,
},
legend cell align = left,
legend columns = 4,
legend image code/.code={%
\draw[#1] (-0.1cm,-0.1cm) rectangle (0.10cm,0.2cm);
},
legend style = {
at={(0.800, 2.50)},
anchor=north,
column sep=1ex
}
]
\nextgroupplot[ylabel style={font=\huge}, ylabel={Results of xyz}]
\addplot[style={corA, fill=corA, mark=none}]
coordinates {
(Program-1, 1.03)
(Program-2, 1.60)
(Program-14, 1.00)
(Program-3, 2.00)
(Program-16, 0.91)
(Program-4, 0.91)
(Program-5, 1.00)
(Program-15, 1.41)
(Program-6, 1.60)
(Program-7, 1.55)
(Program-8, 1.02)
(Program-9, 1.00)
(Program-10, 1.00)
(Program-13, 1.05)
(Program-11, 1.23)
(Program-12, 1.78)
};
\addplot[style={corB,fill=corB,mark=none}]
coordinates {
(Program-1, 0.92)
(Program-2, 1.60)
(Program-14, 1.08)
(Program-3, 1.00)
(Program-16, 0.18)
(Program-4, 0.20)
(Program-5, 0.26)
(Program-15, 0.89)
(Program-6, 0.52)
(Program-7, 0.39)
(Program-8, 1.02)
(Program-9, 1.00)
(Program-10, 1.00)
(Program-13, 0.62)
(Program-11, 0.66)
(Program-12, 0.71)
};
\addplot [style={corC,fill=corC,mark=none}]
coordinates {
(Program-1, 1.03)
(Program-2, 1.60)
(Program-14, 1.00)
(Program-3, 2.00)
(Program-16, 0.07)
(Program-4, 0.09)
(Program-5, 0.38)
(Program-15, 0.49)
(Program-6, 0.73)
(Program-7, 0.52)
(Program-8, 1.02)
(Program-9, 1.00)
(Program-10, 1.00)
(Program-13, 0.14)
(Program-11, 0.16)
(Program-12, 0.21)
};
\addplot [style={corD,fill=corD,mark=none}]
coordinates {
(Program-1, 1.03)
(Program-2, 1.60)
(Program-14, 1.00)
(Program-3, 2.00)
(Program-16, 0.40)
(Program-4, 0.46)
(Program-5, 0.83)
(Program-15, 1.42)
(Program-6, 1.45)
(Program-7, 1.55)
(Program-8, 1.02)
(Program-9, 1.00)
(Program-10, 1.02)
(Program-13, 0.72)
(Program-11, 0.97)
(Program-12, 1.39)
};
\nextgroupplot[
ylabel style={font=\huge},
ylabel={Results of ijk},
xmin={[normalized]2}, % <-- added this line
]
\addplot[style={corA, fill=corA, mark=none}, x tick style={blue}]
coordinates {
% (Program-1, 0.00) % <-- commented this line
(Program-2, 1.46)
(Program-3, 1.04)
(Program-4, 1.15)
(Program-5, 0.88)
(Program-6, 0.95)
(Program-7, 1.41)
(Program-8, 1.07)
(Program-9, 1.04)
(Program-10, 1.00)
(Program-11, 1.30)
(Program-12, 1.38)
};
\addplot[style={corB,fill=corB,mark=none}]
coordinates {
(Program-2, 1.49)
(Program-3, 1.05)
(Program-4, 0.85)
(Program-5, 0.83)
(Program-6, 0.87)
(Program-7, 1.09)
(Program-8, 1.06)
(Program-9, 1.01)
(Program-10, 0.99)
(Program-11, 0.69)
(Program-12, 0.69)
};
\addplot [style={corC,fill=corC,mark=none}]
coordinates {
(Program-2, 1.34)
(Program-3, 1.04)
(Program-4, 0.46)
(Program-5, 0.60)
(Program-6, 0.95)
(Program-7, 1.41)
(Program-8, 1.03)
(Program-9, 0.96)
(Program-10, 0.98)
(Program-11, 0.52)
(Program-12, 0.56)
};
\addplot [style={corD,fill=corD,mark=none}]
coordinates {
(Program-2, 1.34)
(Program-3, 1.04)
(Program-4, 0.85)
(Program-5, 0.83)
(Program-6, 0.95)
(Program-7, 1.41)
(Program-8, 1.04)
(Program-9, 1.04)
(Program-10, 1.00)
(Program-11, 0.88)
(Program-12, 0.95)
};
\legend{A, B, C, D}
\end{groupplot}
\end{tikzpicture}
\end{document}