扩展 pgfplots 边界框

扩展 pgfplots 边界框

这相当简单。我想在不使用enlargelimits或 的情况下扩展 pgfplots 的边界框clip=false

为什么?

防止 pgfplot 线剪辑而不延伸轴

为什么不enlargelimits

因为我希望有一个“整洁”的域,让刻度线也能“整洁”地运行。

丑陋

平均能量损失

\documentclass{article}

\usepackage{pgfplots}

\pgfplotsset{
    no marks,axis lines=middle,
    enlargelimits={abs=1pt},
    minor x tick num=1,
    every x tick/.style={color=black, thin},
    every y tick/.style={color=black, thin},
}

\begin{document}

\begin{center}
    \begin{tikzpicture}
        \begin{axis}[domain=1:2]
            \addplot+{x};
        \end{axis}
    \end{tikzpicture}
\end{center}

\end{document}

一些澄清

我喜欢加粗线条,默认情况下这会导致裁剪问题(请参阅链接的问题)。enlargelimits解决了这个问题,但带来了前面提到的刻度线问题。我希望看到如下所示的内容,而它应该是一个“干净的”(即漂亮的数字)图,例如y=x应该domain=1:3产生更像这样的内容

更好的

同时仍然扩大剪辑边界框。

我希望这能让事情变得更清楚。

更长的版本(抱歉)

为了更全面地说明这个问题,这里有一个更大的例子。

涉及enlargelimits(问题已圈出)

图片3

enlargelimits(问题已圈出)

在此处输入图片描述

微波辐射计 2

\documentclass{article}

\usepackage{pgfplots}
\usetikzlibrary{arrows.meta,calc}

\pgfplotsset{
    compat=newest,
    no marks,
    % -- AXIS
    axis lines=middle,
    axis on top,
    % -- AXIS ARROWS
    inner axis line style={draw=none},
    clip mode=individual,
    execute at end axis={
        \path[tips=proper] let \p1=($(rel axis cs:1,1)-(current axis.origin)$),
        \p2=($(current axis.origin)-(rel axis cs:0,0)$)
        in %\pgfextra{\typeout{\x1,\x2,\y1,\y2}}
        \ifdim\x1>1.5pt
            (current axis.origin) edge[-{Latex[round,length=\ifdim\x1<3mm 1.2mm\else 2mm\fi]}]
            ($({rel axis cs:1,0} |- {current axis.origin})+($(1.36mm,0)-(0,0)$)$)
        \fi
        \ifdim\x2>1.5pt
            (current axis.origin) edge[-{Latex[round,length=\ifdim\x2<3mm 1.2mm\else 2mm\fi]}]
            ($({rel axis cs:0,0} |- {current axis.origin})+($(-1.36mm,0)-(0,0)$)$)
        \fi
        \ifdim\y1>1.5pt
            (current axis.origin) edge[-{Latex[round,length=\ifdim\y1<3mm 1.2mm\else 2mm\fi]}]
            ($({rel axis cs:0,1} -| {current axis.origin})+($(0,1.36mm)-(0,0)$)$)
        \fi
        \ifdim\y2>1.5pt
            (current axis.origin) edge[-{Latex[round,length=\ifdim\y2<3mm 1.2mm\else 2mm\fi]}]
            ($({rel axis cs:0,0} -| {current axis.origin})+($(0,-1.36mm)-(0,0)$)$)
        \fi;
    },
    % % -- TICKS
    minor x tick num=1,
    every x tick/.style={color=black, thin},
    every y tick/.style={color=black, thin},
    tick align=outside,
    %
    every axis plot/.append style={
        very thick,
        line cap=round
    },
    samples=100,
    enlargelimits={abs=1pt}, % prevent clipping of plot lines
    % inner axis line style={shorten >=0.6pt, shorten <=0.6pt},
}

\begin{document}

\begin{center}
    \begin{tikzpicture}
        \begin{axis}[domain=1:2,small]
            \addplot+{x};
        \end{axis}
    \end{tikzpicture}
    \begin{tikzpicture}
        \begin{axis}[domain=1:2,small]
            \addplot+{x^2/2-x};
        \end{axis}
    \end{tikzpicture}
\end{center}

\end{document}

相关内容