2 个 Tikz,1 个图

2 个 Tikz,1 个图

我想将 2 个 Tikz 合并到一个图中,并为每个 Tikz 加上标题。我试过了,subfigure但似乎没有用。我试图让两个图并排显示,每个图下都有一个标题。非常感谢任何帮助。

\begin{tikzpicture}[font=\small]
    \begin{axis}[
      ybar,
      height=8cm,
      width=6cm,
      bar width=15pt,
      xlabel={$c$},
      ylabel={Number of primes},
      ymin=0,
      ytick=\empty,
      xtick=data,
      axis x line=bottom,
      axis y line=left,
      enlarge x limits=0.2,
      symbolic x coords={0,1,2},
      xticklabel style={anchor=base,yshift=-\baselineskip},
      nodes near coords={\pgfmathprintnumber\pgfplotspointmeta}
    ]
      \addplot[fill=white] coordinates {
        (0,295)
        (1,175)
        (2,20)
      };
    \end{axis}
\end{tikzpicture}
%\caption{40-bit primes} \label{40bits}
\begin{tikzpicture}[font=\small]
    \begin{axis}[
      ybar,
      height=8cm,
      width=7cm,
      bar width=15pt,
      xlabel={$c$},
      ylabel={Number of primes},
      ymin=0,
      ytick=\empty,
      xtick=data,
      axis x line=bottom,
      axis y line=left,
      enlarge x limits=0.2,
      symbolic x coords={0,1,2,3,4},
      xticklabel style={anchor=base,yshift=-\baselineskip},
      nodes near coords={\pgfmathprintnumber\pgfplotspointmeta}
    ]
      \addplot[fill=white] coordinates {
        (0,182)
        (1,215)
        (2,75)
        (3,17)
        (4,1)
      };
    \end{axis}
\end{tikzpicture}
%\caption{41-bit primes} \label{41bits}

答案1

这里有一个利用包和环境\subcaption的命令的可能性(参见subcaptionminipage文档;如果您更喜欢另一种可能性,那么还有专用的subfigure环境subtable(如第 5 页所述)。

\documentclass{article}

\usepackage{pgfplots}
\usepackage{subcaption}

\begin{document}

\begin{figure}
\centering
\begin{minipage}[b]{.49\linewidth}
\centering
\begin{tikzpicture}[font=\small]
    \begin{axis}[
      ybar,
      height=8cm,
      width=6cm,
      bar width=15pt,
      xlabel={$c$},
      ylabel={Number of primes},
      ymin=0,
      ytick=\empty,
      xtick=data,
      axis x line=bottom,
      axis y line=left,
      enlarge x limits=0.2,
      symbolic x coords={0,1,2},
      xticklabel style={anchor=base,yshift=-\baselineskip},
      nodes near coords={\pgfmathprintnumber\pgfplotspointmeta}
    ]
      \addplot[fill=white] coordinates {
        (0,295)
        (1,175)
        (2,20)
      };
    \end{axis}
\end{tikzpicture}
\subcaption{40-bit primes}\label{40bits}
\end{minipage}
\begin{minipage}[b]{.49\linewidth}
\centering
\begin{tikzpicture}[font=\small]
    \begin{axis}[
      ybar,
      height=8cm,
      width=7cm,
      bar width=15pt,
      xlabel={$c$},
      ylabel={Number of primes},
      ymin=0,
      ytick=\empty,
      xtick=data,
      axis x line=bottom,
      axis y line=left,
      enlarge x limits=0.2,
      symbolic x coords={0,1,2,3,4},
      xticklabel style={anchor=base,yshift=-\baselineskip},
      nodes near coords={\pgfmathprintnumber\pgfplotspointmeta}
    ]
      \addplot[fill=white] coordinates {
        (0,182)
        (1,215)
        (2,75)
        (3,17)
        (4,1)
      };
    \end{axis}
\end{tikzpicture}
\subcaption{41-bit primes} \label{41bits}
\end{minipage}
\end{figure}

\end{document}

在此处输入图片描述


编辑

\subcaption在回答评论部分中您的问题时,您可以通过更新\thesubfigure命令和使用命令来更改格式的外观\captionsetup

为了达到你想要的结果,添加

\renewcommand\thesubfigure{Fig~\thefigure(\alph{subfigure})}
\captionsetup[sub]{labelformat=simple}

你的序言。

在此处输入图片描述

相关内容