
我想在使用時對繪圖中的一個區域進行著色axes equal=true
。然而,我認為會被遮蔽的部分內容卻沒有。這是我的MWE
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[
axis equal=true,
axis lines=middle,
axis on top,
ticks=none,
xmin=-3,xmax=3,
ymin=-3,ymax=3,
]
\addplot[draw=none,fill=gray!20!white] (-3,-3) -- (-1.125,-3) -- (0.375,3) -- (-3,3) -- cycle;
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
這是我得到的輸出
由於某種原因,使用equal axis=true
會使 x 軸超出該xmin
值,這使得我的陰影區域太小。但是,如果我註解掉equal axis=true
指令,陰影區域看起來與我想要的完全一樣(但我需要指令equal axis=true
來確保我打算繪製的垂直線看起來確實垂直)。
答案1
pgfplots 手冊提到(第 4.10.1 節通用縮放選項,重點是我的):
/pgfplots/axis equal={true,false}
每個單位向量設定為相同的長度,而軸尺寸保持不變。之後,x 和 y 中每個單元的大小比例將相同。
軸限制將擴大以補償縮放效應。
所以確實xmin
不尊重該設定。在範例之後,手冊提到:
配置
axis equal=true
實際上只是設定的一種樣式unit vector ratio=1 1 1, unit rescale keep size=true
。
抬頭看unit rescale keep size
:
/pgfplots/unit rescale keep size=true|false|unless limits declared
在預設配置中,pgfplots 保持原始軸尺寸,即使單位向量比率涉及不同的縮放。它透過擴大限制來做到這一點。
設定此項可以unless limits declared
防止xmin
更改。我不能 100% 確定此設定(與 組合unit vector ratio=1 1 1
)實際上會創建相等的軸,但它似乎有效。代碼:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[
%axis equal=true,
unit vector ratio=1 1 1,
unit rescale keep size=unless limits declared,
axis lines=middle,
axis on top,
ticks=none,
xmin=-3,xmax=3,
ymin=-3,ymax=3,
]
\addplot[draw=none,fill=gray!20!white] (-3,-3) -- (-1.125,-3) -- (0.375,3) -- (-3,3) -- cycle;
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}