分组条形图,四个条形图位于一个面板中

分组条形图,四个条形图位于一个面板中

我正在尝试在单个面板页面中显示所有四个图表。另外,我希望看到我的图表在单个框架中非常专业地进行投影演示。谢谢。

\documentclass{article}

\usepackage{amsmath}
\usepackage{caption}
\usepackage{pgfplots}

\pgfplotsset{compat=1.9}

\begin{document}
\begin{figure}[H]
\centering
\resizebox{12cm}{!}{%
\begin{tikzpicture}%[font=\normalsize]
\begin{axis}
[xbar,width=22cm,height=12cm,bar width=20pt,enlargelimits=0.20,
nodes near coords,
nodes near coords align=horizontal, 
%xmajorgrids = true,
point meta=x * 1, % The displayed number.
xlabel={\textbf{Percentage of Cost}},
tick align=outside,
xtick={0,5,...,100}, 
ytick={1,...,5},
yticklabels={Penalty Cost, Fixed Cost, Operating and Maintenance Cost, Purchase Cost}]
\addplot[draw=red,fill=red!50]
coordinates {(0,1) (4.1,2) (16.8,3) (54.4,4)};
\addlegendentry{\text{MRI Scanning Machine}}

\addplot[draw=blue, fill=blue!50] 
coordinates {(14.5,1) (4.6,2) (1.3,3) (4.3,4)};
\addlegendentry{\text{CT Scanning Machine}}

\end{axis}
\end{tikzpicture}
}
\captionsetup{font={footnotesize}}
\caption{Percentages of Cost Components for MRI and CT scanning machines}
\end{figure}
\begin{figure}[H]
\centering
\resizebox{12cm}{!}{%
\begin{tikzpicture}%[font=\normalsize]
\begin{axis}
[xbar,width=22cm,height=12cm,bar width=20pt,enlargelimits=0.20,
nodes near coords,
nodes near coords align=horizontal,
point meta=x * 1, % The displayed number.
xlabel={\textbf{Percentage of Cost}},
tick align=outside,
xtick={0,5,...,100}, 
ytick={1,...,5},
yticklabels={Penalty Cost, Fixed Cost, Operating and Maintenance Cost, Purchase Cost}]
\addplot[draw=red,fill=red!50]
coordinates {(26.9,1) (3.5,2) (9.0,3) (34.4,4)};
\addlegendentry{\text{MRI Scanning Machine}}

\addplot[draw=blue, fill=blue!50] 
coordinates {(18.6,1) (3.3,2) (0.9,3) (3.4,4)};
\addlegendentry{\text{CT Scanning Machine}}

\end{axis}
\end{tikzpicture}
}
\captionsetup{font={footnotesize}}
\caption{Percentages of Cost Components for MRI and CT scanning machines}
\end{figure}

\begin{figure}[H]
\centering
\resizebox{12cm}{!}{%
\begin{tikzpicture}%[font=\normalsize]
\begin{axis}
[xbar,width=22cm,height=12cm,bar width=20pt,enlargelimits=0.20,
nodes near coords,
nodes near coords align=horizontal,
point meta=x * 1, % The displayed number.
xlabel={\textbf{Percentage of Cost}},
tick align=outside,
xtick={0,5,...,100}, 
ytick={1,...,5},
yticklabels={Penalty Cost, Fixed Cost, Operating and Maintenance Cost, Purchase Cost}]
\addplot[draw=red,fill=red!50]
coordinates {(0.0,1) (11.5,2) (22.3,3) (60.8,4)};
\addlegendentry{\text{MRI Scanning Machine}}

\addplot[draw=blue, fill=blue!50] 
coordinates {(0.0,1) (1.2,2) (2.3,3) (1.9,4)};
\addlegendentry{\text{CT Scanning Machine}}

\end{axis}
\end{tikzpicture}
}
\captionsetup{font={footnotesize}}
\caption{Percentages of Cost Components for MRI and CT scanning machines}
\end{figure}

\begin{figure}[H]
\centering
\resizebox{12cm}{!}{%
\begin{tikzpicture}%[font=\normalsize]
\begin{axis}
[xbar,width=22cm,height=12cm,bar width=20pt,enlargelimits=0.20,
nodes near coords,
nodes near coords align=horizontal,
point meta=x * 1, % The displayed number.
xlabel={\textbf{Percentage of Cost}},
tick align=outside,
xtick={0,5,...,100}, 
ytick={1,...,5},
yticklabels={Penalty Cost, Fixed Cost, Operating and Maintenance Cost, Purchase Cost}]
\addplot[draw=red,fill=red!50]
coordinates {(0.0,1) (9.8,2) (31.6,3) (49.6,4)};
\addlegendentry{\text{MRI Scanning Machine}}

\addplot[draw=blue, fill=blue!50] 
coordinates {(0.0,1) (2.6,2) (1.8,3) (4.6,4)};
\addlegendentry{\text{CT Scanning Machine}}

\end{axis}
\end{tikzpicture}
}
\captionsetup{font={footnotesize}}
\caption{Percentages of Cost Components for MRI and CT scanning machines}
\end{figure}
\end{document}

答案1

正如评论中提到的,将所有这些图放到一个框架上非常困难。这是groupplots库中的方法 »pgf图“。它当然需要根据使用情况进行修改”投影机« 主题。但它可能是一个很好的起点。

一般来说,需要对图例进行一些调整(例如,其位置以及条目中的一些缩写,以使其变小)。也许您想将完整的图片放入环境中figure。由于\tiny字体大小太大,因此4pt选择了新的字体大小,以便在演示模式下可读。

\documentclass[smaller,professionalfonts]{beamer}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}

\pgfplotsset{compat=1.9}

\begin{document}

\begin{frame}
  \begin{tikzpicture}
    \begin{groupplot}[
      group style={group size=2 by 2},
      group/horizontal sep=2cm,
      group/vertical sep=3pc,
      group/every plot/.style={
        legend style={inner sep=0.5pt},
        xbar,
        bar width=8pt,
        enlargelimits=0.20,
        nodes near coords,
        nodes near coords align=horizontal,
        point meta=x * 1,
        xlabel={\textbf{Percentage of Cost}},
        tick align=outside,
        major tick length=2pt,
        xtick={0,5,...,100},
        ytick={1,...,5},
        yticklabels={Penalty Cost, Fixed Cost, Operating and Maintenance Cost, Purchase Cost},
        y tick label style={text width=1.25cm,align=right}
      },
      width=0.45\textwidth,
      height=0.45\textheight,
      /tikz/font=\fontsize{4}{5}\selectfont  % new font size
    ]
      \nextgroupplot
        \addplot[draw=red,fill=red!50] coordinates {(0,1) (4.1,2) (16.8,3) (54.4,4)};
        \addlegendentry{MRI Scanning Machine}

        \addplot[draw=blue, fill=blue!50] coordinates {(14.5,1) (4.6,2) (1.3,3) (4.3,4)};
        \addlegendentry{CT Scanning Machine}

      \nextgroupplot
        \addplot[draw=red,fill=red!50] coordinates {(26.9,1) (3.5,2) (9.0,3) (34.4,4)};
        \addlegendentry{MRI Scanning Machine}

        \addplot[draw=blue, fill=blue!50] coordinates {(18.6,1) (3.3,2) (0.9,3) (3.4,4)};
        \addlegendentry{CT Scanning Machine}

      \nextgroupplot
        \addplot[draw=red,fill=red!50] coordinates {(0.0,1) (11.5,2) (22.3,3) (60.8,4)};
        \addlegendentry{MRI Scanning Machine}

        \addplot[draw=blue, fill=blue!50] coordinates {(0.0,1) (1.2,2) (2.3,3) (1.9,4)};
        \addlegendentry{CT Scanning Machine}

      \nextgroupplot
        \addplot[draw=red,fill=red!50] coordinates {(0.0,1) (9.8,2) (31.6,3) (49.6,4)};
        \addlegendentry{MRI Scanning Machine}

        \addplot[draw=blue, fill=blue!50] coordinates {(0.0,1) (2.6,2) (1.8,3) (4.6,4)};
        \addlegendentry{CT Scanning Machine}
    \end{groupplot}
  \end{tikzpicture}
\end{frame}

\end{document}

在此处输入图片描述


附录

正如评论中提到的,这会将图表分成两个框架。此外,还有一些增强功能可以使它们看起来更好一些。

  • 减少bar width
  • 通过固定的最小值和最大值在 x 轴上进行相同的缩放,以获得更多相似性
  • 将条形图稍微移离 y 轴enlarge x limits
  • 图例移至剧情右下角

进一步的可能的增强留给感兴趣的读者去完成。

\documentclass[smaller,professionalfonts]{beamer}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}

\pgfplotsset{compat=1.9}

\begin{document}

\begin{frame}
  \begin{tikzpicture}
    \begin{groupplot}[
      group style={group size=1 by 2},
      group/horizontal sep=2cm,
      group/vertical sep=3pc,
      group/every plot/.style={
        legend style={inner sep=0.5pt},
        legend pos=south east,
        xbar,
        bar width=6pt,
        enlarge x limits=0.01,
        enlarge y limits=0.2,
        nodes near coords,
        nodes near coords align=horizontal,
        point meta=x * 1,
        xlabel={\textbf{Percentage of Cost}},
        tick align=outside,
        major tick length=2pt,
        xmin=0,
        xmax=65,
        xtick={0,5,...,65},
        ytick={1,...,5},
        yticklabels={Penalty Cost,Fixed Cost,Operating and Maintenance Cost,Purchase Cost},
        y tick label style={text width=1.3cm,align=right}
      },
      width=0.95\textwidth,
      height=0.45\textheight,
      /tikz/font=\tiny
    ]
      \nextgroupplot
        \addplot[draw=red,fill=red!50] coordinates {(0,1) (4.1,2) (16.8,3) (54.4,4)};
        \addlegendentry{MRI Scanning Machine}

        \addplot[draw=blue, fill=blue!50] coordinates {(14.5,1) (4.6,2) (1.3,3) (4.3,4)};
        \addlegendentry{CT Scanning Machine}

      \nextgroupplot
        \addplot[draw=red,fill=red!50] coordinates {(26.9,1) (3.5,2) (9.0,3) (34.4,4)};
        \addlegendentry{MRI Scanning Machine}

        \addplot[draw=blue,fill=blue!50] coordinates {(18.6,1) (3.3,2) (0.9,3) (3.4,4)};
        \addlegendentry{CT Scanning Machine}
    \end{groupplot}
  \end{tikzpicture}
\end{frame}

\begin{frame}
  \begin{tikzpicture}
    \begin{groupplot}[
      group style={group size=1 by 2},
      group/horizontal sep=2cm,
      group/vertical sep=3pc,
      group/every plot/.style={
        legend style={inner sep=0.5pt},
        legend pos=south east,
        xbar,
        bar width=6pt,
        enlarge x limits=0.01,
        enlarge y limits=0.2,
        nodes near coords,
        nodes near coords align=horizontal,
        point meta=x * 1,
        xlabel={\textbf{Percentage of Cost}},
        tick align=outside,
        major tick length=2pt,
        xmin=0,
        xmax=65,
        xtick={0,5,...,65},
        ytick={1,...,5},
        yticklabels={Penalty Cost,Fixed Cost,Operating and Maintenance Cost,Purchase Cost},
        y tick label style={text width=1.3cm,align=right}
      },
      width=0.95\textwidth,
      height=0.45\textheight,
      /tikz/font=\tiny,
    ]
      \nextgroupplot
        \addplot[draw=red,fill=red!50] coordinates {(0.0,1) (11.5,2) (22.3,3) (60.8,4)};
        \addlegendentry{MRI Scanning Machine}

        \addplot[draw=blue, fill=blue!50] coordinates {(0.0,1) (1.2,2) (2.3,3) (1.9,4)};
        \addlegendentry{CT Scanning Machine}

      \nextgroupplot
        \addplot[draw=red,fill=red!50] coordinates {(0.0,1) (9.8,2) (31.6,3) (49.6,4)};
        \addlegendentry{MRI Scanning Machine}

        \addplot[draw=blue, fill=blue!50] coordinates {(0.0,1) (2.6,2) (1.8,3) (4.6,4)};
        \addlegendentry{CT Scanning Machine}
    \end{groupplot}
  \end{tikzpicture}
\end{frame}

\end{document}

在此处输入图片描述 在此处输入图片描述

相关内容