无法并排放置曲线

无法并排放置曲线

我想在同一个图中显示两条曲线,如下所示: 在此处输入图片描述

\documentclass{article}

 \usepackage{siunitx}
 \sisetup{per=slash, load=abbr}
 % GRAPHICS
 \usepackage{tikz}
 \usepackage{pgfplots}
 \pgfplotsset{width=7cm,compat=1.3}
 \begin{document}

 \begin{tikzpicture}
 \pgfplotsset{
  scale only axis,
 %scaled x ticks=base 10:1,
 xmin=1, xmax=12,
 y axis style/.style={
    yticklabel style=#1,
    ylabel style=#1,
    y axis line style=#1,
    ytick style=#1
}
}
\begin{axis}[
xtick={0,...,12},ytick={0.0,0.1,...,1},
%legend style={at={(0.1,-0.2)}, anchor=north west},
axis y line*=left,
y axis style=red,
ymin=0, ymax=0.8, grid=both,
xlabel= Number ,
ylabel=$R^2$,
 y tick label style={
    /pgf/number format/.cd,
    fixed,
    fixed zerofill,
    precision=1,
    /tikz/.cd
 },
 ]
 \addplot[smooth,red]%mark=x,
coordinates{
(12, 0.75)
(11, 0.749)
(10, 0.749)
(9, 0.748)
(8, 0.748)
(7, 0.746)
(6, 0.739)
(5, 0.733)
(4, 0.697)
(3, 0.674)
(2, 0.668)
};
\label{plot_one}
\end{axis}
\begin{axis}[
ytick={0.75,0.8,0.85,0.9,0.95,1.0},
 legend style={at={(0.2,-0.2)}, anchor=north west},
 axis y line*=right,
 y axis style=blue,
 axis x line=none,
 ymin=0.70, ymax=1,
 ylabel=Con,
  y tick label style={
    /pgf/number format/.cd,
    fixed,
    fixed zerofill,
    precision=2,
    /tikz/.cd
  },legend columns=-1
  ]
  \addlegendimage{/pgfplots/refstyle=plot_one}
  \addlegendentry{R}
   \addplot[smooth,blue]%,mark=*
   coordinates{
   (12, 0.725)
   (11, 0.726)
   (10, 0.73)
   (9, 0.732)
   (8, 0.746)
   (7,0.754)
   (6, 0.832)
   (5, 0.828)
   (4, 0.912)
   (3, 0.96)
   (2, 0.992)
   };
  \addlegendentry{Con}
  \end{axis}

  \end{tikzpicture}

  \begin{tikzpicture}
  \pgfplotsset{
   scale only axis,
   scaled x ticks=base 10:3,
   xmin=0, xmax=0.06
  }

 \begin{axis}[
 axis y line*=left,
 ymin=0, ymax=80,
 xlabel=$Q/\si{\m\cubed\per\s}$,
 ylabel=$H/\si{\m}$,
 ]
\addplot[smooth,mark=x,blue]
 coordinates{
(0,68.6)
(0.0148,72)
(0.0295,68.6)
(0.0441,53.4)
(0.059,22.8)
}; \label{Hplot}
\end{axis}

 \begin{axis}[
 axis y line*=right,
 axis x line=none,
 ymin=0, ymax=100,
 ylabel=$\eta/\si{\percent}$
]
\addlegendimage{/pgfplots/refstyle=Hplot}\addlegendentry{$H$}
\addplot[smooth,mark=*,red]
 coordinates{
(0,0)
(0.0148,48)
(0.0295,66)
(0.0441,66)
(0.059,45.0)
}; \addlegendentry{$\eta$}
\end{axis}

\end{tikzpicture}
\end{document} 

答案1

width=7cm两张图片并排放置太多了。而且你不应该在它们之间留空行

 \end{tikzpicture}
  % <------------------no blank line
  \begin{tikzpicture}

相当于\par

对于标题和朋友,您可以使用subcation包。宽度width=3cm和 es 之间没有空白行,subcaptionbox我们有

\documentclass{article}

 \usepackage{siunitx}
 \sisetup{per=slash, load=abbr}
 % GRAPHICS
 \usepackage{tikz}
 \usepackage{pgfplots}
 \pgfplotsset{width=3cm,compat=1.3}  %%<--------------- width here
 \usepackage{subcaption}
 \begin{document}
\begin{figure}
\subcaptionbox{figure1a\label{1a}}[0.5\textwidth][b]
{
 \begin{tikzpicture}
 \pgfplotsset{
  scale only axis,
 %scaled x ticks=base 10:1,
 xmin=1, xmax=12,
 y axis style/.style={
    yticklabel style=#1,
    ylabel style=#1,
    y axis line style=#1,
    ytick style=#1
}
}
\begin{axis}[
xtick={0,...,12},ytick={0.0,0.1,...,1},
%legend style={at={(0.1,-0.2)}, anchor=north west},
axis y line*=left,
y axis style=red,
ymin=0, ymax=0.8, grid=both,
xlabel= Number ,
ylabel=$R^2$,
 y tick label style={
    /pgf/number format/.cd,
    fixed,
    fixed zerofill,
    precision=1,
    /tikz/.cd
 },
 ]
 \addplot[smooth,red]%mark=x,
coordinates{
(12, 0.75)
(11, 0.749)
(10, 0.749)
(9, 0.748)
(8, 0.748)
(7, 0.746)
(6, 0.739)
(5, 0.733)
(4, 0.697)
(3, 0.674)
(2, 0.668)
};
\label{plot_one}
\end{axis}
\begin{axis}[
ytick={0.75,0.8,0.85,0.9,0.95,1.0},
 legend style={at={(0.2,-0.2)}, anchor=north west},
 axis y line*=right,
 y axis style=blue,
 axis x line=none,
 ymin=0.70, ymax=1,
 ylabel=Con,
  y tick label style={
    /pgf/number format/.cd,
    fixed,
    fixed zerofill,
    precision=2,
    /tikz/.cd
  },legend columns=-1
  ]
  \addlegendimage{/pgfplots/refstyle=plot_one}
  \addlegendentry{R}
   \addplot[smooth,blue]%,mark=*
   coordinates{
   (12, 0.725)
   (11, 0.726)
   (10, 0.73)
   (9, 0.732)
   (8, 0.746)
   (7,0.754)
   (6, 0.832)
   (5, 0.828)
   (4, 0.912)
   (3, 0.96)
   (2, 0.992)
   };
  \addlegendentry{Con}
  \end{axis}
  \end{tikzpicture}
  }
  %%<------------------------------no blank line
  \subcaptionbox{figure1a\label{1b}}[0.5\textwidth][b]
{
  \begin{tikzpicture}
  \pgfplotsset{
   scale only axis,
   scaled x ticks=base 10:3,
   xmin=0, xmax=0.06
  }

 \begin{axis}[
 axis y line*=left,
 ymin=0, ymax=80,
 xlabel=$Q/\si{\m\cubed\per\s}$,
 ylabel=$H/\si{\m}$,
 ]
\addplot[smooth,mark=x,blue]
 coordinates{
(0,68.6)
(0.0148,72)
(0.0295,68.6)
(0.0441,53.4)
(0.059,22.8)
}; \label{Hplot}
\end{axis}
 \begin{axis}[
 axis y line*=right,
 axis x line=none,
 ymin=0, ymax=100,
 ylabel=$\eta/\si{\percent}$
]
\addlegendimage{/pgfplots/refstyle=Hplot}\addlegendentry{$H$}
\addplot[smooth,mark=*,red]
 coordinates{
(0,0)
(0.0148,48)
(0.0295,66)
(0.0441,66)
(0.059,45.0)
}; \addlegendentry{$\eta$}
\end{axis}

\end{tikzpicture}
}
\caption{my figure}
\end{figure}
\end{document}

在此处输入图片描述

如果您希望[t]在第一和第二个子图中使用顶部对齐,例如

\subcaptionbox{figure1a\label{1a}}[0.5\textwidth][t] %<--- 这里

答案2

我更喜欢使用 tabular 而不是 subfig、subcaption 或 subfloat。

\documentclass{article}

 \usepackage{siunitx}
 \sisetup{per=slash, load=abbr}
 % GRAPHICS
 \usepackage{graphicx}% for \resizebox
 \usepackage{caption}% for \captionof
 \usepackage{pgfplots}
 \pgfplotsset{width=7cm,compat=1.3}
 \begin{document}

 \noindent\resizebox{\textwidth}{!}{% your plots are too big
 \begin{tabular}{@{}cc@{}}
 \begin{tikzpicture}[baseline=(current bounding box.north)]% align tops
 \pgfplotsset{
  scale only axis,
 %scaled x ticks=base 10:1,
 xmin=1, xmax=12,
 y axis style/.style={
    yticklabel style=#1,
    ylabel style=#1,
    y axis line style=#1,
    ytick style=#1
}
}
\begin{axis}[
xtick={0,...,12},ytick={0.0,0.1,...,1},
%legend style={at={(0.1,-0.2)}, anchor=north west},
axis y line*=left,
y axis style=red,
ymin=0, ymax=0.8, grid=both,
xlabel= Number ,
ylabel=$R^2$,
 y tick label style={
    /pgf/number format/.cd,
    fixed,
    fixed zerofill,
    precision=1,
    /tikz/.cd
 },
 ]
 \addplot[smooth,red]%mark=x,
coordinates{
(12, 0.75)
(11, 0.749)
(10, 0.749)
(9, 0.748)
(8, 0.748)
(7, 0.746)
(6, 0.739)
(5, 0.733)
(4, 0.697)
(3, 0.674)
(2, 0.668)
};
\label{plot_one}
\end{axis}
\begin{axis}[
ytick={0.75,0.8,0.85,0.9,0.95,1.0},
 legend style={at={(0.2,-0.2)}, anchor=north west},
 axis y line*=right,
 y axis style=blue,
 axis x line=none,
 ymin=0.70, ymax=1,
 ylabel=Con,
  y tick label style={
    /pgf/number format/.cd,
    fixed,
    fixed zerofill,
    precision=2,
    /tikz/.cd
  },legend columns=-1
  ]
  \addlegendimage{/pgfplots/refstyle=plot_one}
  \addlegendentry{R}
   \addplot[smooth,blue]%,mark=*
   coordinates{
   (12, 0.725)
   (11, 0.726)
   (10, 0.73)
   (9, 0.732)
   (8, 0.746)
   (7,0.754)
   (6, 0.832)
   (5, 0.828)
   (4, 0.912)
   (3, 0.96)
   (2, 0.992)
   };
  \addlegendentry{Con}
  \end{axis}

  \end{tikzpicture}&% no blank line allowed
  \begin{tikzpicture}[baseline=(current bounding box.north)]
  \pgfplotsset{
   scale only axis,
   scaled x ticks=base 10:3,
   xmin=0, xmax=0.06
  }

 \begin{axis}[
 axis y line*=left,
 ymin=0, ymax=80,
 xlabel=$Q/\si{\m\cubed\per\s}$,
 ylabel=$H/\si{\m}$,
 ]
 \addplot[smooth,mark=x,blue]
 coordinates{
(0,68.6)
(0.0148,72)
(0.0295,68.6)
(0.0441,53.4)
(0.059,22.8)
}; \label{Hplot}
\end{axis}

 \begin{axis}[
 axis y line*=right,
 axis x line=none,
 ymin=0, ymax=100,
 ylabel=$\eta/\si{\percent}$
]
\addlegendimage{/pgfplots/refstyle=Hplot}\addlegendentry{$H$}
\addplot[smooth,mark=*,red]
 coordinates{
(0,0)
(0.0148,48)
(0.0295,66)
(0.0441,66)
(0.059,45.0)
}; \addlegendentry{$\eta$}
\end{axis}

\end{tikzpicture}\\
\stepcounter{figure}% before caption
\rule{0pt}{2em}% insrease gap
(a) Fig \thefigure.a&(b) Fig \thefigure.b%
\addtocounter{figure}{-1}\\
\end{tabular}}
\captionof{figure}{Example}
\end{document} 

对齐并带有标题

相关内容