如何避免通过插图绘制图形

如何避免通过插图绘制图形

我有一张需要插图的图。使用 pdfplots 我几乎完成了,但主图是通过插图绘制的。

主和插入

我怎样才能避免通过插图进行绘图?另外,是否可以将插图的 x/y 标签移近其各自的轴?

代码副本:

\documentclass{standalone}

% Setting graphing environment
\usepackage{pgfplots}
\pgfplotsset{compat=newest} 
\pgfplotsset{plot coordinates/math parser=false}

\begin{document}

% declare inset:
\newsavebox\inset

\begin{tikzpicture} []

    % declare constants:
    \pgfmathsetmacro\omega{1}

    % declare equations:
    \pgfmathdeclarefunction{rho}{2}{\pgfmathparse{% density
        sin(deg(2*pi*#1))*cos(deg(2*pi*#2))*exp(-\omega*#2)}}

    % make plot for inset:
    \savebox\inset{
        \begin{axis} [ tiny, 
            domain=0:2, samples=50,
            xmin=0, xmax=2, ymin=-1, ymax=1, no markers,
            xlabel=dimensionless time\, /\, $\theta$,
            ylabel=peak density\, /\, $\rho$,
        ]
        \addplot [] {rho(0.25,x)};
        \end{axis}
    }

    \begin{axis} [
        domain=0:1, samples=50,
        xmin=0, xmax=1, ymin=-1, ymax=1, no markers,
        xlabel=dimensionless coordinate\, /\, $x$,
        ylabel=dimensionless density\, /\, $\rho$,
        clip=false
    ]
        \addplot [] {rho(x,0)} [yshift=-6pt] node [pos=0.25] {\footnotesize $0$};
        \addplot [] {rho(x,0.5)} [yshift=-6pt] node [pos=0.25] {\footnotesize $0.5$};
        \addplot [] {rho(x,1)} [yshift=-6pt] node [pos=0.25] {\footnotesize $1$};
        \addplot [] {rho(x,1.5)} [yshift=-6pt] node [pos=0.25] {\footnotesize $1.5$};
        \addplot [] {rho(x,2)} [yshift=-6pt] node [pos=0.25] {\footnotesize $2$};
        \addplot [] {rho(x,2.5)} [yshift=-6pt] node [pos=0.25] {\footnotesize $2.5$};

    \end{axis}

    \node [anchor=north east] at (4.3,3.7) {\usebox\inset};

\end{tikzpicture}

答案1

要将轴标签移近轴,可以使用xlabel shiftylabel shift键。为了给插图留出空间,您可以扩展 y 轴上外部图的范围,例如最多 2。

\documentclass{standalone}

% Setting graphing environment
\usepackage{pgfplots}
\pgfplotsset{compat=newest} 
\pgfplotsset{plot coordinates/math parser=false}

\begin{document}

% declare inset:
\newsavebox\inset

\begin{tikzpicture} []

    % declare constants:
    \pgfmathsetmacro\omega{1}

    % declare equations:
    \pgfmathdeclarefunction{rho}{2}{\pgfmathparse{% density
        sin(deg(2*pi*#1))*cos(deg(2*pi*#2))*exp(-\omega*#2)}}

    % make plot for inset:
    \savebox\inset{
        \begin{axis} [tiny,
            domain=0:2, samples=50,
            xmin=0, xmax=2, ymin=-1, ymax=1, no markers,
            xlabel=dimensionless time\, /\, $\theta$,
            xlabel shift = -1ex,
            ylabel=peak density\, /\, $\rho$,
            ylabel shift = -1.4ex,
        ]
        \addplot [] {rho(0.25,x)};
        \end{axis}
    }

    \begin{axis} [
        domain=0:1, samples=50,
        xmin=0, xmax=1, ymin=-1, ymax=2, no markers,
        xlabel=dimensionless coordinate\, /\, $x$,
        ylabel=dimensionless density\, /\, $\rho$,
        clip=false
    ]
        \addplot [] {rho(x,0)} [yshift=-6pt] node [pos=0.25] {\footnotesize $0$};
        \addplot [] {rho(x,0.5)} [yshift=-6pt] node [pos=0.25] {\footnotesize $0.5$};
        \addplot [] {rho(x,1)} [yshift=-6pt] node [pos=0.25] {\footnotesize $1$};
        \addplot [] {rho(x,1.5)} [yshift=-6pt] node [pos=0.25] {\footnotesize $1.5$};
        \addplot [] {rho(x,2)} [yshift=-6pt] node [pos=0.25] {\footnotesize $2$};
        \addplot [] {rho(x,2.5)} [yshift=-6pt] node [pos=0.25] {\footnotesize $2.5$};

    \end{axis}

    \node [anchor=north east] at (4.3,3.7) {\usebox\inset};

\end{tikzpicture}
\end{document}

结果

此外,您可能希望减小ymax外部图的 ,并使用 选项axis background/.style={fill=white}(或者其他颜色,如果您喜欢)作为插图,以便它“隐藏”在其后面绘制的主图线条。例如,下图是使用 生成的ymax=1.4

结果2

相关内容