将 3 个图表合并为 1 个并添加附加标签

将 3 个图表合并为 1 个并添加附加标签

我想制作下图: 在此处输入图片描述

到目前为止,我只在单独的图中绘制了每条曲线。我怎样才能将它们合并为一条?我怎样才能使用虚线,我怎样才能添加“第一阶段”、“第二阶段”等,以及如何添加“严格增加”标签?

我到目前为止的代码分别是:对于 TP 曲线

\begin{tikzpicture}
\begin{axis}[
  xmin = 0,
  xmax = 8,
  ymin = 0,
  ymax = 18, 
  axis lines = left,
  xlabel = $L$,
  ylabel = $Q$
  ]
  \addplot+[mark = none] coordinates {%
    (0,0) 
    (1,3)
    (2,8)
    (3,12)
    (4,15)
    (5,17)
    (6,17)
    (7,16)};
\coordinate (A) at (axis cs:0,0);
\coordinate (B) at (axis cs:1,3);
\coordinate (C) at (axis cs:2,8);
\coordinate (D) at (axis cs:3,12);
\coordinate (E) at (axis cs:4,15);
\coordinate (F) at (axis cs:5,17);
\coordinate (G) at (axis cs:6,17);
\coordinate (H) at (axis cs:7,16);
\end{axis}
\end{tikzpicture}

对于 AP:

\begin{tikzpicture}
\begn{axis}[
  xmin = 0,
  xmax = 8,
  ymin = 0,
  ymax = 18, 
  axis lines = left,
  xlabel = $L$,
  ylabel = $Q$
  ]
  \addplot+[mark = none] coordinates {%
    (0,0) 
    (1,3)
    (2,4)
    (3,4)
    (4,3.75)
    (5,3.4)
    (6,2.8)
    (7,2.2)};
\coordinate (A) at (axis cs:0,0);
\coordinate (B) at (axis cs:1,3);
\coordinate (C) at (axis cs:2,4);
\coordinate (D) at (axis cs:3,4);
\coordinate (E) at (axis cs:4,3.75);
\coordinate (F) at (axis cs:5,3.4);
\coordinate (G) at (axis cs:6,2.8);
\coordinate (H) at (axis cs:7,2.2);
\end{axis}
\end{tikzpicture}

对于 MP:

\begin{tikzpicture}
\begin{axis}[
  xmin = 0,
  xmax = 8,
  ymin = 0,
  ymax = 18, 
  axis lines = left,
  xlabel = $L$,
  ylabel = $Q$
  ]
  \addplot+[mark = none] coordinates {%
    (0,0) 
    (1,3)
    (2,5)
    (3,4)
    (4,3)
    (5,2)
    (6,0)
    (7,-1)};
\coordinate (A) at (axis cs:0,0);
\coordinate (B) at (axis cs:1,3);
\coordinate (C) at (axis cs:2,5);
\coordinate (D) at (axis cs:3,4);
\coordinate (E) at (axis cs:4,3);
\coordinate (F) at (axis cs:5,2);
\coordinate (G) at (axis cs:6,0);
\coordinate (H) at (axis cs:7,-1);
\end{axis}
\end{tikzpicture}

最后,您是否知道是否有一个 Excel 插件可以将其图表转换为 Latex 代码(因为有一个用于表格的插件)?

答案1

要将所有图表合并为一张图片,只需将它们全部添加到一个轴环境中。

您可以使用以下方法添加虚线和标签:

\draw[dashed] (axis cs:2,0) -- (axis cs:2,20); % dashed line
\node at (axis cs:1,18) {1st stage};           % label

以下是完整示例:

\documentclass[border=.5cm]{standalone}

\title{pgfplots - motor}

\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
  axis lines=middle,
  xmin = 0,
  xmax = 8,
  ymin = -5,
  ymax = 20,      
  xlabel = $L$,
  ylabel = $Q$,
  xlabel near ticks,
  ylabel near ticks,
  extra y ticks       = {-5,5,10,15,20},
  extra y tick labels = ,
  extra y tick style  = {grid = major},
  legend style={at={(axis cs:8.5,10)},anchor=west}
  ]
  \addplot+[mark = none, smooth] coordinates {%
    (0,0) 
    (1,3)
    (2,8)
    (3,12)
    (4,15)
    (5,17)
    (6,17)
    (7,16)};
  \addlegendentry{TP}
  \addplot+[mark = none, smooth] coordinates {%
    (0,0) 
    (1,3)
    (2,4)
    (3,4)
    (4,3.75)
    (5,3.4)
    (6,2.8)
    (7,2.2)};
  \addlegendentry{AP}
  \addplot+[mark = none, smooth] coordinates {%
    (0,0) 
    (1,3)
    (2,5)
    (3,4)
    (4,3)
    (5,2)
    (6,0)
    (7,-1)};
  \addlegendentry{MP}

    \draw[dashed] (axis cs:2,0) -- (axis cs:2,20);
    \draw[dashed] (axis cs:6,0) -- (axis cs:6,20);

    \node at (axis cs:1,18) {1st stage};
    \node at (axis cs:4,18) {2nd stage};
    \node at (axis cs:7,18) {3rd stage};

    \node[rotate=45] at (axis cs:.7,3.8)
        {\tiny \parbox{1.2cm}{strictly\\ increasing}};

\end{axis}

\end{tikzpicture}

\end{document}

pgf图

相关内容