Tikz:对齐两个图形的原点

Tikz:对齐两个图形的原点

我创建了两个图形,但原点的垂直位置不一样。如何才能使它们具有相同的垂直水平?

这是我的 MWE。此外,如果您对情节有任何其他评论,欢迎提出。

\documentclass[12pt,reqno]{article}

\usepackage{amsfonts}
\usepackage[top=20mm,bottom=20mm,left=20mm,right=20mm]{geometry}
\usepackage{graphicx}
\usepackage{float}
\usepackage{subfig}

\usepackage{pgfplots}
\pgfplotsset{compat=1.15}

\definecolor{mc1}{rgb}{0.368417,0.506779,0.709798}
\definecolor{mc2}{rgb}{0.880722,0.611041,0.142051}
\newcommand{\R}{\mathbb{R}}
\begin{document}

\begin{figure}[ht]
  \centering
    \subfloat[The surface $z=f(x,y)$.]{\label{sespex2fig1a}
      \begin{tikzpicture}[declare function={sgn(\x)=(\x>=0)*1+(\x<=0)*(-1);f(\x,\y)=(\x<=0)*(-\y)+(\x>=0)*((abs{\y}>=\x^2)*(sgn(\y)*(sqrt{abs{\y}}+1)*\x-\y)+(abs{\y}<=\x^2)*(sgn(\y)*sqrt{abs{\y}}));}]
        \begin{axis}[
          width=100mm,
          height=60mm,
          view={120}{75},
          axis lines=center,
          xtick={-1,0,1},
          x tick label style={opacity=0.4},
          xmin=-1.25,
          xmax=1.25,
          domain=-1:1,
          xlabel={$t$},
          xlabel style={opacity=0.4},
          x axis line style={opacity=0.6},
          ytick={-1,0,1},
          y tick label style={opacity=0.4},
          ymin=-1.25,
          ymax=1.25,
          y domain=-1:1,
          ylabel={$y$},
          ylabel style={opacity=0.4},
          y axis line style={opacity=0.6},
          %ztick={-1,1},
          zticklabels={\empty},
          z tick label style={opacity=0.4},
          zmin=-0.75,
          zmax=0.75,
          zlabel={$z$},
          zlabel style={opacity=0.4},
          z axis line style={opacity=0.6},
        ]
          \addplot3[surf,color=mc1,opacity=0.2,samples=25,samples y=25,faceted color=mc1!40]{f(x,y)};
          \draw[variable=\t,domain=-1:1,samples=2,color=mc2,thick,dashed] plot (axis cs:0,\t,-\t);
          \draw[variable=\t,domain=0:1,samples=11,color=mc2,thick,dashed] plot (axis cs:\t,\t^2,\t);
          \draw[variable=\t,domain=0:1,samples=11,color=mc2,thick,dashed] plot (axis cs:\t,-\t^2,-\t);
        \end{axis}
      \end{tikzpicture}
    }
    \qquad
    \subfloat[The parses of the domain of $f$.]{\label{sespex2fig1b}
      \begin{tikzpicture}
        \begin{axis}[
          width=100mm,
          height=60mm,
          view={0}{90},
          axis lines=center,
          xtick={-1,0,1},
          x tick label style={opacity=0.4},
          xmin=-1.25,
          xmax=1.25,
          domain=-1:1,
          xlabel={$t$},
          xlabel style={opacity=0.4},
          x axis line style={opacity=0.6},
          ytick={-1,0,1},
          y tick label style={opacity=0.4},
          ymin=-1.25,
          ymax=1.25,
          y domain=-1:1,
          ylabel={$y$},
          ylabel style={opacity=0.4},
          y axis line style={opacity=0.6},
          ztick={-1,1},
          zticklabels={\empty},
          z tick label style={opacity=0.4},
          zmin=-1.25,
          zmax=1.25,
          zlabel={$z$},
          zlabel style={opacity=0.4},
          z axis line style={opacity=0.6},
        ]
          \addplot3[surf,color=mc1,opacity=0.2,samples=25,samples y=25,faceted color=mc1!40]{0};
          \draw[variable=\t,domain=-1:1,samples=2,color=mc2,very thick,dashed] plot (axis cs:0,\t,0);
          \draw[variable=\t,domain=0:1,samples=11,color=mc2,thick,dashed] plot (axis cs:\t,\t^2,0);
          \draw[variable=\t,domain=0:1,samples=11,color=mc2,thick,dashed] plot (axis cs:\t,-\t^2,0);
        \end{axis}
      \end{tikzpicture}
    }
    \caption{Graphics of $f:\R^{2}\to\R$.}\label{sespex2fig1}
\end{figure}

\end{document} 

在此处输入图片描述

答案1

看看下面哪一个数字更符合你的预期:

在此处输入图片描述

对于第二张图,我放大了第一张子图像的高度;

\documentclass[12pt,reqno]{article}

\usepackage{amsfonts}
\newcommand{\R}{\mathbb{R}}
\usepackage[top=20mm,bottom=20mm,left=20mm,right=20mm]{geometry}
\usepackage{graphicx}
\usepackage{float}
\usepackage{subfig}

\usepackage{pgfplots}
\pgfplotsset{compat=1.15}

\definecolor{mc1}{rgb}{0.368417,0.506779,0.709798}
\definecolor{mc2}{rgb}{0.880722,0.611041,0.142051}

\begin{document}

\begin{figure}[ht]
  \centering
    \subfloat[The surface $z=f(x,y)$.]{\label{sespex2fig1a}
      \begin{tikzpicture}[baseline=(current bounding box.center),% <---- added
      declare function = {sgn(\x)=(\x>=0)*1+(\x<=0)*(-1);f(\x,\y)=(\x<=0)*(-\y)+(\x>=0)*((abs{\y}>=\x^2)*(sgn(\y)*(sqrt{abs{\y}}+1)*\x-\y)+(abs{\y}<=\x^2)*(sgn(\y)*sqrt{abs{\y}}));}]
        \begin{axis}[
          width=100mm,
          height=60mm,
          view={120}{75},
          axis lines=center,
          xtick={-1,0,1},
          x tick label style={opacity=0.4},
          xmin=-1.25,
          xmax=1.25,
          domain=-1:1,
          xlabel={$t$},
          xlabel style={opacity=0.4},
          x axis line style={opacity=0.6},
          ytick={-1,0,1},
          y tick label style={opacity=0.4},
          ymin=-1.25,
          ymax=1.25,
          y domain=-1:1,
          ylabel={$y$},
          ylabel style={opacity=0.4},
          y axis line style={opacity=0.6},
          %ztick={-1,1},
          zticklabels={\empty},
          z tick label style={opacity=0.4},
          zmin=-0.75,
          zmax=0.75,
          zlabel={$z$},
          zlabel style={opacity=0.4},
          z axis line style={opacity=0.6},
        ]
          \addplot3[surf,color=mc1,opacity=0.2,samples=25,samples y=25,faceted color=mc1!40]{f(x,y)};
          \draw[variable=\t,domain=-1:1,samples=2,color=mc2,thick,dashed] plot (axis cs:0,\t,-\t);
          \draw[variable=\t,domain=0:1,samples=11,color=mc2,thick,dashed] plot (axis cs:\t,\t^2,\t);
          \draw[variable=\t,domain=0:1,samples=11,color=mc2,thick,dashed] plot (axis cs:\t,-\t^2,-\t);
        \end{axis}
      \end{tikzpicture}
    }
    \qquad
    \subfloat[The parses of the domain of $f$.]{\label{sespex2fig1b}
      \begin{tikzpicture}[baseline=(current bounding box.center)]% <---- added
        \begin{axis}[
          width=100mm,
          height=60mm,
          view={0}{90},
          axis lines=center,
          xtick={-1,0,1},
          x tick label style={opacity=0.4},
          xmin=-1.25,
          xmax=1.25,
          domain=-1:1,
          xlabel={$t$},
          xlabel style={opacity=0.4},
          x axis line style={opacity=0.6},
          ytick={-1,0,1},
          y tick label style={opacity=0.4},
          ymin=-1.25,
          ymax=1.25,
          y domain=-1:1,
          ylabel={$y$},
          ylabel style={opacity=0.4},
          y axis line style={opacity=0.6},
          ztick={-1,1},
          zticklabels={\empty},
          z tick label style={opacity=0.4},
          zmin=-1.25,
          zmax=1.25,
          zlabel={$z$},
          zlabel style={opacity=0.4},
          z axis line style={opacity=0.6},
        ]
          \addplot3[surf,color=mc1,opacity=0.2,samples=25,samples y=25,faceted color=mc1!40]{0};
          \draw[variable=\t,domain=-1:1,samples=2,color=mc2,very thick,dashed] plot (axis cs:0,\t,0);
          \draw[variable=\t,domain=0:1,samples=11,color=mc2,thick,dashed] plot (axis cs:\t,\t^2,0);
          \draw[variable=\t,domain=0:1,samples=11,color=mc2,thick,dashed] plot (axis cs:\t,-\t^2,0);
        \end{axis}
      \end{tikzpicture}
    }
    \caption{Graphics of $f:\R^{2}\to\R$.}
    \label{sespex2fig1}
\end{figure}

\begin{figure}[ht]
  \centering
    \subfloat[The surface $z=f(x,y)$.]{\label{sespex2fig1a}
      \begin{tikzpicture}[baseline=(current bounding box.center),% <---- added
      declare function = {sgn(\x)=(\x>=0)*1+(\x<=0)*(-1);f(\x,\y)=(\x<=0)*(-\y)+(\x>=0)*((abs{\y}>=\x^2)*(sgn(\y)*(sqrt{abs{\y}}+1)*\x-\y)+(abs{\y}<=\x^2)*(sgn(\y)*sqrt{abs{\y}}));}]
        \begin{axis}[
          width=100mm,
          height=84mm,
          view={120}{75},
          axis lines=center,
          xtick={-1,0,1},
          x tick label style={opacity=0.4},
          xmin=-1.25,
          xmax=1.25,
          domain=-1:1,
          xlabel={$t$},
          xlabel style={opacity=0.4},
          x axis line style={opacity=0.6},
          ytick={-1,0,1},
          y tick label style={opacity=0.4},
          ymin=-1.25,
          ymax=1.25,
          y domain=-1:1,
          ylabel={$y$},
          ylabel style={opacity=0.4},
          y axis line style={opacity=0.6},
          %ztick={-1,1},
          zticklabels={\empty},
          z tick label style={opacity=0.4},
          zmin=-0.75,
          zmax=0.75,
          zlabel={$z$},
          zlabel style={opacity=0.4},
          z axis line style={opacity=0.6},
        ]
          \addplot3[surf,color=mc1,opacity=0.2,samples=25,samples y=25,faceted color=mc1!40]{f(x,y)};
          \draw[variable=\t,domain=-1:1,samples=2,color=mc2,thick,dashed] plot (axis cs:0,\t,-\t);
          \draw[variable=\t,domain=0:1,samples=11,color=mc2,thick,dashed] plot (axis cs:\t,\t^2,\t);
          \draw[variable=\t,domain=0:1,samples=11,color=mc2,thick,dashed] plot (axis cs:\t,-\t^2,-\t);
        \end{axis}
      \end{tikzpicture}
    }
    \qquad
    \subfloat[The parses of the domain of $f$.]{\label{sespex2fig1b}
      \begin{tikzpicture}[baseline=(current bounding box.center)]% <---- added
        \begin{axis}[
          width=100mm,
          height=60mm,
          view={0}{90},
          axis lines=center,
          xtick={-1,0,1},
          x tick label style={opacity=0.4},
          xmin=-1.25,
          xmax=1.25,
          domain=-1:1,
          xlabel={$t$},
          xlabel style={opacity=0.4},
          x axis line style={opacity=0.6},
          ytick={-1,0,1},
          y tick label style={opacity=0.4},
          ymin=-1.25,
          ymax=1.25,
          y domain=-1:1,
          ylabel={$y$},
          ylabel style={opacity=0.4},
          y axis line style={opacity=0.6},
          ztick={-1,1},
          zticklabels={\empty},
          z tick label style={opacity=0.4},
          zmin=-1.25,
          zmax=1.25,
          zlabel={$z$},
          zlabel style={opacity=0.4},
          z axis line style={opacity=0.6},
        ]
          \addplot3[surf,color=mc1,opacity=0.2,samples=25,samples y=25,faceted color=mc1!40]{0};
          \draw[variable=\t,domain=-1:1,samples=2,color=mc2,very thick,dashed] plot (axis cs:0,\t,0);
          \draw[variable=\t,domain=0:1,samples=11,color=mc2,thick,dashed] plot (axis cs:\t,\t^2,0);
          \draw[variable=\t,domain=0:1,samples=11,color=mc2,thick,dashed] plot (axis cs:\t,-\t^2,0);
        \end{axis}
      \end{tikzpicture}
    }
    \caption{Graphics of $f:\R^{2}\to\R$.}
    \label{sespex2fig1}
\end{figure}

\end{document}

附录:考虑到下面的 John Kormylo 评论,你可以针对第一个数字写道:

\documentclass[12pt,reqno]{article}

\usepackage{amsfonts}
\newcommand{\R}{\mathbb{R}}
\usepackage[top=20mm,bottom=20mm,left=20mm,right=20mm]{geometry}
\usepackage{graphicx}
\usepackage{float}
\usepackage{subfig}

\usepackage{pgfplots}
\pgfplotsset{compat=1.15}

\definecolor{mc1}{rgb}{0.368417,0.506779,0.709798}
\definecolor{mc2}{rgb}{0.880722,0.611041,0.142051}

\begin{document}

\begin{figure}[ht]
  \centering
    \subfloat[The surface $z=f(x,y)$.]{\label{sespex2fig1a}
      \begin{tikzpicture}[baseline=(origin),% <---- suggestion of John Kormylo
      declare function = {sgn(\x)=(\x>=0)*1+(\x<=0)*(-1);f(\x,\y)=(\x<=0)*(-\y)+(\x>=0)*((abs{\y}>=\x^2)*(sgn(\y)*(sqrt{abs{\y}}+1)*\x-\y)+(abs{\y}<=\x^2)*(sgn(\y)*sqrt{abs{\y}}));}]
        \begin{axis}[
          width=100mm,
          height=60mm,
          view={120}{75},
          axis lines=center,
          xtick={-1,0,1},
          x tick label style={opacity=0.4},
          xmin=-1.25,
          xmax=1.25,
          domain=-1:1,
          xlabel={$t$},
          xlabel style={opacity=0.4},
          x axis line style={opacity=0.6},
          ytick={-1,0,1},
          y tick label style={opacity=0.4},
          ymin=-1.25,
          ymax=1.25,
          y domain=-1:1,
          ylabel={$y$},
          ylabel style={opacity=0.4},
          y axis line style={opacity=0.6},
          %ztick={-1,1},
          zticklabels={\empty},
          z tick label style={opacity=0.4},
          zmin=-0.75,
          zmax=0.75,
          zlabel={$z$},
          zlabel style={opacity=0.4},
          z axis line style={opacity=0.6},
        ]
        \coordinate (origin) at (axis cs: 0,0,0); % suggestion of John Kormylo
          \addplot3[surf,color=mc1,opacity=0.2,samples=25,samples y=25,faceted color=mc1!40]{f(x,y)};
          \draw[variable=\t,domain=-1:1,samples=2,color=mc2,thick,dashed] plot (axis cs:0,\t,-\t);
          \draw[variable=\t,domain=0:1,samples=11,color=mc2,thick,dashed] plot (axis cs:\t,\t^2,\t);
          \draw[variable=\t,domain=0:1,samples=11,color=mc2,thick,dashed] plot (axis cs:\t,-\t^2,-\t);
        \end{axis}
      \end{tikzpicture}
    }
    \qquad
    \subfloat[The parses of the domain of $f$.]{\label{sespex2fig1b}
      \begin{tikzpicture}[baseline=(origin)]% <---- added
        \begin{axis}[
          width=100mm,
          height=60mm,
          view={0}{90},
          axis lines=center,
          xtick={-1,0,1},
          x tick label style={opacity=0.4},
          xmin=-1.25,
          xmax=1.25,
          domain=-1:1,
          xlabel={$t$},
          xlabel style={opacity=0.4},
          x axis line style={opacity=0.6},
          ytick={-1,0,1},
          y tick label style={opacity=0.4},
          ymin=-1.25,
          ymax=1.25,
          y domain=-1:1,
          ylabel={$y$},
          ylabel style={opacity=0.4},
          y axis line style={opacity=0.6},
          ztick={-1,1},
          zticklabels={\empty},
          z tick label style={opacity=0.4},
          zmin=-1.25,
          zmax=1.25,
          zlabel={$z$},
          zlabel style={opacity=0.4},
          z axis line style={opacity=0.6},
        ]
        \coordinate (origin) at (axis cs: 0,0,0); % suggestion of John Kormylo
          \addplot3[surf,color=mc1,opacity=0.2,samples=25,samples y=25,faceted color=mc1!40]{0};
          \draw[variable=\t,domain=-1:1,samples=2,color=mc2,very thick,dashed] plot (axis cs:0,\t,0);
          \draw[variable=\t,domain=0:1,samples=11,color=mc2,thick,dashed] plot (axis cs:\t,\t^2,0);
          \draw[variable=\t,domain=0:1,samples=11,color=mc2,thick,dashed] plot (axis cs:\t,-\t^2,0);
        \end{axis}
      \end{tikzpicture}
    }
    \caption{Graphics of $f:\R^{2}\to\R$.}
    \label{sespex2fig1}
\end{figure}
\end{document}

获得的结果是相同的。可能的优点是,您对origin 图像中的位置具有更大的灵活性(未经测试)。

相关内容