使轴对齐

使轴对齐

我正在制作下面的图形:

有问题的图形

我希望右上角的绘图的 y 轴与左侧旋转绘图的 x 轴完全对齐(即刻度对齐)。我还想去掉左侧绘图中似乎存在的多余“0”。代码如下:

\documentclass{scrartcl}

\usepackage{pgfplots}
 \pgfplotsset{compat=1.12}
\begin{document}

\pgfmathdeclarefunction{gauss}{2}{%
  \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}

\begin{tikzpicture}[scale = 1, remember picture]
  \begin{axis}[axis line style = thick, smooth, no markers,
    axis lines = left, axis line style={->}, xmin = 0, xmax = 4, name
    = main plot]
   \addplot[samples = 200] gnuplot{norm((x-2)/0.75)};
   \coordinate (A) at (axis cs:1.75, 0.3694413);
   \coordinate (C) at (axis cs:2.25, 0.6305587);
   \draw[dashed] (A) -- (0, 0.3694413);
   \draw[dashed] (C) -- (0, 0.6305587);
   \draw[thick, blue, <->] (0.1, 0.38) -- (0.1, 0.62);
  \end{axis}
   \begin{axis}[at={(main plot.below south west)}, yshift=-0.3cm,
     anchor = north west, axis line style = thick, smooth, no markers,
    axis lines = left, axis line style={->}, xmin = 0, xmax = 4, y = 6cm/3, ymin = 0, ymax = 1.0]
    \addplot[samples = 400] {gauss(2, 0.75^2)};
    \coordinate (B) at (axis cs:1.75,0);
    \coordinate (D) at (axis cs:2.25,0);
    \draw[thick, blue, <->] (1.76, 0.1) -- (2.24, 0.1);
   \end{axis}
   \draw[dashed] (A) -- (B);
   \draw[dashed] (C) -- (D);
    \begin{axis}[xshift = -3cm, axis line style = thick, smooth, no
      markers, y = 6cm/3, y tick label style={rotate=45,
        anchor=north east, inner sep=0mm}, 
    axis lines = left, axis line style={->}, xmin = 0, xmax = 1, ymin = 0, ymax = 1, 
   rotate around={90:(0,0)}
    ]
    \addplot[blue, thick] {1};
    \end{axis}
\end{tikzpicture}
\end{document}

答案1

height将右上图的设置为与width左上图的相同的显式值。要将所有轴缩放到相同大小,请将底部轴的高度设置为相同的值。据我了解,两个相邻轴上的刻度是相同的,因此您可以从左上图的 x 轴上删除刻度标签。这也会删除您提到的额外零。

在此处输入图片描述

\documentclass{scrartcl}

\usepackage{pgfplots}
 \pgfplotsset{compat=1.12}
\begin{document}

\pgfmathdeclarefunction{gauss}{2}{%
  \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}

\begin{tikzpicture}[scale = 1, remember picture]

  \begin{axis}[axis line style = thick, smooth, no markers,
    axis lines = left, axis line style={->}, xmin = 0, xmax = 4, name
    = main plot,
    height=6cm]
   \addplot[samples = 200] gnuplot{norm((x-2)/0.75)};
   \coordinate (A) at (axis cs:1.75, 0.3694413);
   \coordinate (C) at (axis cs:2.25, 0.6305587);
   \draw[dashed] (A) -- (0, 0.3694413);
   \draw[dashed] (C) -- (0, 0.6305587);
   \draw[thick, blue, <->] (0.1, 0.38) -- (0.1, 0.62);
  \end{axis}

   \begin{axis}[at={(main plot.below south west)}, yshift=-0.3cm,
     anchor = north west, axis line style = thick, smooth, no markers,
    axis lines = left, axis line style={->}, xmin = 0, xmax = 4, y = 6cm/3, ymin = 0, ymax = 1.0,
    height=6cm]
    \addplot[samples = 400] {gauss(2, 0.75^2)};
    \coordinate (B) at (axis cs:1.75,0);
    \coordinate (D) at (axis cs:2.25,0);
    \draw[thick, blue, <->] (1.76, 0.1) -- (2.24, 0.1);
   \end{axis}

   \draw[dashed] (A) -- (B);
   \draw[dashed] (C) -- (D);

    \begin{axis}[xshift = -3cm, axis line style = thick, smooth, no
      markers, y = 6cm/3, y tick label style={rotate=45,
        anchor=north east, inner sep=0mm},
    axis lines = left, axis line style={->}, xmin = 0, xmax = 1, ymin = 0, ymax = 1, 
    rotate around={90:(0,0)},
    width=6cm,xticklabels={},xtick={0,0.2,...,0.8}
    ]
    \addplot[blue, thick] {1};
    \end{axis}
\end{tikzpicture}
\end{document}

相关内容