水平条形图中的条形分组

水平条形图中的条形分组

我想评估不同材料的一种属性,这些材料分为 6 组。为此,我想制作一个水平条形图。我已经对图表进行了编码,创建了一个虚拟刻度,以便将所有材料的名称放在垂直轴上(之前,它只显示第一个图的材料名称)。我无法像我创建的比例那样将各组彼此等距离地分开。

我使用的代码如下:

\begin{tikzpicture}
\hspace*{-4.5cm} 
    \begin{axis}[
    xlabel={zT},
    enlargelimits=0.05,
    legend style={at={(0.50,-0.10)},
      anchor=north,legend columns=-1},
   symbolic y coords={Bi\textsubscript{2}Te\textsubscript{2.7}Se\textsubscript{0.3},Bi\textsubscript{0.5}Te\textsubscript{1.5}Se\textsubscript{3},{(BiSb)}\textsubscript{2}Te\textsubscript{3},Bi\textsubscript{0.52}Te\textsubscript{1.48}Se\textsubscript{3},Bi\textsubscript{0.48}Te\textsubscript{1.52}Se\textsubscript{3},Bi\textsubscript{0.4}Te\textsubscript{1.6}Se\textsubscript{3},AgPb\textsubscript{18}SbTe\textsubscript{20},Pb\textsubscript{9.6}Sb\textsubscript{0.2}Te\textsubscript{3}Se\textsubscript{7},{(Pb\textsubscript{0.95}Sn\textsubscript{0.05}Te)}\textsubscript{0.92}{(PbS)}\textsubscript{0.08},K\textsubscript{0.95}Pb\textsubscript{20}Sb\textsubscript{1.2}Te\textsubscript{22},Ag\textsubscript{0.53}Pb\textsubscript{18}Sb\textsubscript{1.2}Te\textsubscript{20},Ag\textsubscript{0.5}Pb\textsubscript{6}Sn\textsubscript{2}Sb\textsubscript{0.2}Te\textsubscript{10},Na\textsubscript{0.95}Pb\textsubscript{20}SbTe\textsubscript{22},Tl\textsubscript{0.02}Pb\textsubscript{0.98}Te,Pb\textsubscript{0.98}Na\textsubscript{0.02}Te\textsubscript{0.85}Se\textsubscript{0.15},PbTe-SrTe doped with Na,PbSe:Al\textsubscript{0.01},Na doped PbSe,Pb\textsubscript{0.92}Sr\textsubscript{0.08}Se,Yb\textsubscript{0.19}Co\textsubscript{4}Sb\textsubscript{12},In\textsubscript{0.25}Co\textsubscript{4}Sb\textsubscript{12},CoSb\textsubscript{2.75}Sn\textsubscript{0.05}Te\textsubscript{0.20},Yb\textsubscript{0.2}Co\textsubscript{4}Sb\textsubscript{12.3},Na\textsubscript{0.48}Co\textsubscript{4}Sb\textsubscript{12},Ba\textsubscript{0.14}In\textsubscript{0.23}Co\textsubscript{4}Sb\textsubscript{11.84},Ba\textsubscript{0.08}La\textsubscript{0.05}Yb\textsubscript{0.04}Co\textsubscript{4}Sb\textsubscript{12},Sr\textsubscript{0.12}Ba\textsubscript{0.18}DD\textsubscript{0.39}Fe\textsubscript{3}CoSb\textsubscript{12},Hf\textsubscript{0.5}Zr\textsubscript{0.25}Ti\textsubscript{0.25}NiSn\textsubscript{0.99}Sb\textsubscript{0.01},Hf\textsubscript{0.8}Ti\textsubscript{0.2}CoSb\textsubscript{0.8}Sn\textsubscript{0.2},Si\textsubscript{80}Ge\textsubscript{20} n-type,Si\textsubscript{80}Ge\textsubscript{20} p-type},
ytick=data]

%Dummy graph:
\newcommand{\dummy}{0.715}% some value in the x range
    \addplot [xbar,transparent,only marks] coordinates {
    (\dummy,Bi\textsubscript{2}Te\textsubscript{2.7}Se\textsubscript{0.3})
    (\dummy,Bi\textsubscript{0.5}Te\textsubscript{1.5}Se\textsubscript{3})
    (\dummy,{(BiSb)}\textsubscript{2}Te\textsubscript{3})
    (\dummy,Bi\textsubscript{0.52}Te\textsubscript{1.48}Se\textsubscript{3})
    (\dummy,Bi\textsubscript{0.48}Te\textsubscript{1.52}Se\textsubscript{3})
    (\dummy,Bi\textsubscript{0.4}Te\textsubscript{1.6}Se\textsubscript{3})

    (\dummy,AgPb\textsubscript{18}SbTe\textsubscript{20})
    (\dummy,Pb\textsubscript{9.6}Sb\textsubscript{0.2}Te\textsubscript{3}Se\textsubscript{7})
    (\dummy,{(Pb\textsubscript{0.95}Sn\textsubscript{0.05}Te)}\textsubscript{0.92}{(PbS)}\textsubscript{0.08})
    (\dummy,K\textsubscript{0.95}Pb\textsubscript{20}Sb\textsubscript{1.2}Te\textsubscript{22})
    (\dummy,Ag\textsubscript{0.53}Pb\textsubscript{18}Sb\textsubscript{1.2}Te\textsubscript{20})
    (\dummy,Ag\textsubscript{0.5}Pb\textsubscript{6}Sn\textsubscript{2}Sb\textsubscript{0.2}Te\textsubscript{10})
    (\dummy,Na\textsubscript{0.95}Pb\textsubscript{20}SbTe\textsubscript{22})
    (\dummy,Tl\textsubscript{0.02}Pb\textsubscript{0.98}Te)
    (\dummy,Pb\textsubscript{0.98}Na\textsubscript{0.02}Te\textsubscript{0.85}Se\textsubscript{0.15})
    (\dummy,PbTe-SrTe doped with Na)

    (\dummy,Yb\textsubscript{0.19}Co\textsubscript{4}Sb\textsubscript{12})
    (\dummy,In\textsubscript{0.25}Co\textsubscript{4}Sb\textsubscript{12})
    (\dummy,CoSb\textsubscript{2.75}Sn\textsubscript{0.05}Te\textsubscript{0.20})
    (\dummy,Yb\textsubscript{0.2}Co\textsubscript{4}Sb\textsubscript{12.3})
    (\dummy,Na\textsubscript{0.48}Co\textsubscript{4}Sb\textsubscript{12})
    (\dummy,Ba\textsubscript{0.14}In\textsubscript{0.23}Co\textsubscript{4}Sb\textsubscript{11.84})
    (\dummy,Ba\textsubscript{0.08}La\textsubscript{0.05}Yb\textsubscript{0.04}Co\textsubscript{4}Sb\textsubscript{12})
    (\dummy,Sr\textsubscript{0.12}Ba\textsubscript{0.18}DD\textsubscript{0.39}Fe\textsubscript{3}CoSb\textsubscript{12})

    (\dummy,PbSe:Al\textsubscript{0.01})
    (\dummy,Na doped PbSe)
    (\dummy,Pb\textsubscript{0.92}Sr\textsubscript{0.08}Se)

    (\dummy,Hf\textsubscript{0.5}Zr\textsubscript{0.25}Ti\textsubscript{0.25}NiSn\textsubscript{0.99}Sb\textsubscript{0.01})
    (\dummy,Hf\textsubscript{0.8}Ti\textsubscript{0.2}CoSb\textsubscript{0.8}Sn\textsubscript{0.2})        

    (\dummy,Si\textsubscript{80}Ge\textsubscript{20} n-type)
    (\dummy,Si\textsubscript{80}Ge\textsubscript{20} p-type)
};

%BiTe alloys:
\addplot[xbar,fill=purple] coordinates {
    (1.04,Bi\textsubscript{2}Te\textsubscript{2.7}Se\textsubscript{0.3})
    (1.40,Bi\textsubscript{0.5}Te\textsubscript{1.5}Se\textsubscript{3})
    (1.47,{(BiSb)}\textsubscript{2}Te\textsubscript{3})
    (1.56,Bi\textsubscript{0.52}Te\textsubscript{1.48}Se\textsubscript{3})
    (1.50,Bi\textsubscript{0.48}Te\textsubscript{1.52}Se\textsubscript{3})
    (1.80,Bi\textsubscript{0.4}Te\textsubscript{1.6}Se\textsubscript{3})
};
%PbTe alloys:
\addplot[xbar,fill=violet] coordinates {
    (2.20,AgPb\textsubscript{18}SbTe\textsubscript{20})
    (1.20,Pb\textsubscript{9.6}Sb\textsubscript{0.2}Te\textsubscript{3}Se\textsubscript{7})
    (1.50,{(Pb\textsubscript{0.95}Sn\textsubscript{0.05}Te)}\textsubscript{0.92}{(PbS)}\textsubscript{0.08})
    (1.60,K\textsubscript{0.95}Pb\textsubscript{20}Sb\textsubscript{1.2}Te\textsubscript{22})
    (1.70,Ag\textsubscript{0.53}Pb\textsubscript{18}Sb\textsubscript{1.2}Te\textsubscript{20})
    (1.45,Ag\textsubscript{0.5}Pb\textsubscript{6}Sn\textsubscript{2}Sb\textsubscript{0.2}Te\textsubscript{10})
    (1.70,Na\textsubscript{0.95}Pb\textsubscript{20}SbTe\textsubscript{22})
    (1.50,Tl\textsubscript{0.02}Pb\textsubscript{0.98}Te)
    (1.80,Pb\textsubscript{0.98}Na\textsubscript{0.02}Te\textsubscript{0.85}Se\textsubscript{0.15})
    (2.20,PbTe-SrTe doped with Na)
};
%PbSe alloys:
\addplot[xbar,fill=pink] coordinates {
    (1.00,Yb\textsubscript{0.19}Co\textsubscript{4}Sb\textsubscript{12})
    (1.20,In\textsubscript{0.25}Co\textsubscript{4}Sb\textsubscript{12})
    (1.10,CoSb\textsubscript{2.75}Sn\textsubscript{0.05}Te\textsubscript{0.20})
    (1.30,Yb\textsubscript{0.2}Co\textsubscript{4}Sb\textsubscript{12.3})
    (1.25,Na\textsubscript{0.48}Co\textsubscript{4}Sb\textsubscript{12})
    (1.34,Ba\textsubscript{0.14}In\textsubscript{0.23}Co\textsubscript{4}Sb\textsubscript{11.84})
    (1.70,Ba\textsubscript{0.08}La\textsubscript{0.05}Yb\textsubscript{0.04}Co\textsubscript{4}Sb\textsubscript{12})
    (1.30,Sr\textsubscript{0.12}Ba\textsubscript{0.18}DD\textsubscript{0.39}Fe\textsubscript{3}CoSb\textsubscript{12})
};
%Skutterudites:
\addplot[xbar,fill=orange] coordinates {
    (1.3,PbSe:Al\textsubscript{0.01})
    (1.2,Na doped PbSe)
    (1.5,Pb\textsubscript{0.92}Sr\textsubscript{0.08}Se)
};
%Half-heuslers:
\addplot[xbar,fill=magenta] coordinates {
    (1,Hf\textsubscript{0.5}Zr\textsubscript{0.25}Ti\textsubscript{0.25}NiSn\textsubscript{0.99}Sb\textsubscript{0.01})
    (1,Hf\textsubscript{0.8}Ti\textsubscript{0.2}CoSb\textsubscript{0.8}Sn\textsubscript{0.2})
};   
%Si-Ge alloys:
\addplot[xbar,fill=red] coordinates {
    (1.30,Si\textsubscript{80}Ge\textsubscript{20} n-type)
    (0.95,Si\textsubscript{80}Ge\textsubscript{20} p-type)
};   
 \legend{ ,BiTe alloys,PbTe alloys,PbSe alloys,Skurredites,Half-heuslers,Si-Ge alloys}
 \end{axis}
 \end{tikzpicture}

它看起来像这样

现在的情况

,但我希望它看起来像这样:

我希望它看起来

有办法吗?如果有人能帮忙,我将不胜感激!

答案1

一个快速解决方法是在列表中添加一些空坐标symbolic y coords。例如

Hf\tss{0.8}Ti\tss{0.2}CoSb\tss{0.8}Sn\tss{0.2},,Si\tss{80}Ge\tss{20}

代替

Hf\tss{0.8}Ti\tss{0.2}CoSb\tss{0.8}Sn\tss{0.2},Si\tss{80}Ge\tss{20} 

注意额外的逗号。(我将其定义\tss为 的简写\textsubscript。)

其他一些修改:

  • 我添加了一个height=15cm,使用默认设置时,情况会更加拥挤。您可能需要在自己的代码中删除它。
  • 我没有首先使用虚拟图,而是设置了xmin=0.715, ytick distance=1,tickwidth=0,然后删除了ytick=data

下面的代码输出

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\newcommand\tss\textsubscript %
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    height=15cm, % added, you probably want to remove this
    xmin=0.715, % added
    ytick distance=1, % instead of ytick=data
    tickwidth=0, % to hide the ticks that would otherwise show up between the bars
    xlabel={zT},
    enlargelimits=0.05,
    legend style={at={(0.50,-0.10)},
      anchor=north,legend columns=-1},
   symbolic y coords={Bi\tss{2}Te\tss{2.7}Se\tss{0.3},Bi\tss{0.5}Te\tss{1.5}Se\tss{3},{(BiSb)}\tss{2}Te\tss{3},Bi\tss{0.52}Te\tss{1.48}Se\tss{3},Bi\tss{0.48}Te\tss{1.52}Se\tss{3},Bi\tss{0.4}Te\tss{1.6}Se\tss{3},,AgPb\tss{18}SbTe\tss{20},Pb\tss{9.6}Sb\tss{0.2}Te\tss{3}Se\tss{7},{(Pb\tss{0.95}Sn\tss{0.05}Te)}\tss{0.92}{(PbS)}\tss{0.08},K\tss{0.95}Pb\tss{20}Sb\tss{1.2}Te\tss{22},Ag\tss{0.53}Pb\tss{18}Sb\tss{1.2}Te\tss{20},Ag\tss{0.5}Pb\tss{6}Sn\tss{2}Sb\tss{0.2}Te\tss{10},Na\tss{0.95}Pb\tss{20}SbTe\tss{22},Tl\tss{0.02}Pb\tss{0.98}Te,Pb\tss{0.98}Na\tss{0.02}Te\tss{0.85}Se\tss{0.15},PbTe-SrTe doped with Na,,PbSe:Al\tss{0.01},Na doped PbSe,Pb\tss{0.92}Sr\tss{0.08}Se,,Yb\tss{0.19}Co\tss{4}Sb\tss{12},In\tss{0.25}Co\tss{4}Sb\tss{12},CoSb\tss{2.75}Sn\tss{0.05}Te\tss{0.20},Yb\tss{0.2}Co\tss{4}Sb\tss{12.3},Na\tss{0.48}Co\tss{4}Sb\tss{12},Ba\tss{0.14}In\tss{0.23}Co\tss{4}Sb\tss{11.84},Ba\tss{0.08}La\tss{0.05}Yb\tss{0.04}Co\tss{4}Sb\tss{12},Sr\tss{0.12}Ba\tss{0.18}DD\tss{0.39}Fe\tss{3}CoSb\tss{12},,Hf\tss{0.5}Zr\tss{0.25}Ti\tss{0.25}NiSn\tss{0.99}Sb\tss{0.01},Hf\tss{0.8}Ti\tss{0.2}CoSb\tss{0.8}Sn\tss{0.2},,Si\tss{80}Ge\tss{20} n-type,Si\tss{80}Ge\tss{20} p-type},
]


%BiTe alloys:
\addplot[xbar,fill=purple] coordinates {
    (1.04,Bi\tss{2}Te\tss{2.7}Se\tss{0.3})
    (1.40,Bi\tss{0.5}Te\tss{1.5}Se\tss{3})
    (1.47,{(BiSb)}\tss{2}Te\tss{3})
    (1.56,Bi\tss{0.52}Te\tss{1.48}Se\tss{3})
    (1.50,Bi\tss{0.48}Te\tss{1.52}Se\tss{3})
    (1.80,Bi\tss{0.4}Te\tss{1.6}Se\tss{3})
};
%PbTe alloys:
\addplot[xbar,fill=violet] coordinates {
    (2.20,AgPb\tss{18}SbTe\tss{20})
    (1.20,Pb\tss{9.6}Sb\tss{0.2}Te\tss{3}Se\tss{7})
    (1.50,{(Pb\tss{0.95}Sn\tss{0.05}Te)}\tss{0.92}{(PbS)}\tss{0.08})
    (1.60,K\tss{0.95}Pb\tss{20}Sb\tss{1.2}Te\tss{22})
    (1.70,Ag\tss{0.53}Pb\tss{18}Sb\tss{1.2}Te\tss{20})
    (1.45,Ag\tss{0.5}Pb\tss{6}Sn\tss{2}Sb\tss{0.2}Te\tss{10})
    (1.70,Na\tss{0.95}Pb\tss{20}SbTe\tss{22})
    (1.50,Tl\tss{0.02}Pb\tss{0.98}Te)
    (1.80,Pb\tss{0.98}Na\tss{0.02}Te\tss{0.85}Se\tss{0.15})
    (2.20,PbTe-SrTe doped with Na)
};
%PbSe alloys:
\addplot[xbar,fill=pink] coordinates {
    (1.00,Yb\tss{0.19}Co\tss{4}Sb\tss{12})
    (1.20,In\tss{0.25}Co\tss{4}Sb\tss{12})
    (1.10,CoSb\tss{2.75}Sn\tss{0.05}Te\tss{0.20})
    (1.30,Yb\tss{0.2}Co\tss{4}Sb\tss{12.3})
    (1.25,Na\tss{0.48}Co\tss{4}Sb\tss{12})
    (1.34,Ba\tss{0.14}In\tss{0.23}Co\tss{4}Sb\tss{11.84})
    (1.70,Ba\tss{0.08}La\tss{0.05}Yb\tss{0.04}Co\tss{4}Sb\tss{12})
    (1.30,Sr\tss{0.12}Ba\tss{0.18}DD\tss{0.39}Fe\tss{3}CoSb\tss{12})
};
%Skutterudites:
\addplot[xbar,fill=orange] coordinates {
    (1.3,PbSe:Al\tss{0.01})
    (1.2,Na doped PbSe)
    (1.5,Pb\tss{0.92}Sr\tss{0.08}Se)
};
%Half-heuslers:
\addplot[xbar,fill=magenta] coordinates {
    (1,Hf\tss{0.5}Zr\tss{0.25}Ti\tss{0.25}NiSn\tss{0.99}Sb\tss{0.01})
    (1,Hf\tss{0.8}Ti\tss{0.2}CoSb\tss{0.8}Sn\tss{0.2})
};   
%Si-Ge alloys:
\addplot[xbar,fill=red] coordinates {
    (1.30,Si\tss{80}Ge\tss{20} n-type)
    (0.95,Si\tss{80}Ge\tss{20} p-type)
};   
 \legend{ ,BiTe alloys,PbTe alloys,PbSe alloys,Skurredites,Half-heuslers,Si-Ge alloys}
 \end{axis}
 \end{tikzpicture}
\end{document}

相关内容