Tikz 比例键无法正确缩放坐标

Tikz 比例键无法正确缩放坐标

我使用 tikz 创建了一个图像,但缩放时它无法正确转换坐标,如下图所示。我认为这是因为使用了很多节点来绘制图像,特别是橙色和青色线条,这也是两条未缩放的线条。

Tikz 中的缩放比例

我现在很困惑,因为我创建的其他非常相似的图像确实可以正确缩放。我知道我可以使用诸如 之类的东西resizebox,但我不希望文本缩放。我真的很感激任何帮助 :)

MWE 如下:


\documentclass[IEEEtran]{standalone}
\usepackage{pgfplotstable} % Loads a bunch of packages
\pgfplotsset{compat=newest}
\usetikzlibrary{positioning}
\tikzstyle{help lines}=[thin,gray!40]
%- Define colors to be used 
\definecolor{Blue}{rgb}{0,0,1}%             
\definecolor{Cyan}{rgb}{0.0, 0.72, 0.92}%  
\definecolor{Orange}{rgb}{1.0, 0.49, 0.0}%   
%
\begin{document}
%

    \begin{tikzpicture}[scale=1]
    %- Axis node
    \node[inner sep=0,outer sep=0] (Origin Ax2) {};
        %- Axis
    \begin{scope}[-stealth,very thick]
        \draw (Origin Ax2)  -- +(0,3.5) node[anchor=south east,rotate=90] {Y axis}; % Y-axis
        \draw (Origin Ax2) -- +(4.75,0) node[anchor = north east]{X axis}; % X axis
    \end{scope}

    %- Blue line starting node
    \node[inner sep=0,outer sep=0,right=0.25 of Origin Ax2] (Blue Begins) {};
    %- Blue line
    \begin{scope}[color=Blue,very thick]
        \draw (Blue Begins) -- ++(0,3) node[anchor=north west]{Blue}  -- ++(3.5,0) -- ++(0,-3);
    \end{scope}

    %- Nodes to guide left and right side of the parabolas <- I think the problem might be here (?)
    \node[inner sep=0,outer sep=0,above=1.25 of Blue Begins] (Cyan left anchor) {};
    \node[inner sep=0,outer sep=0,right=3.5 of Cyan left anchor] (Cyan right anchor) {};
    \node[inner sep=0,outer sep=0,above=0.5 of Blue Begins] (Orange left anchor) {};
    \node[inner sep=0,outer sep=0,right=3.5 of Orange left anchor] (Orange right anchor) {};
    
    %- A label
    \node[below right= 0 and 1.5 of Blue Begins] (A) {A};
    \node[above=2.25 of A] (A top) {}; % Maximum of paraboles
    \begin{scope}[ dashed] % Line from (A) to (A top), but it appears waaay higher so modified by hand
        \draw (A) -- ++(0,2.8);
    \end{scope}
    
    %- Cyan line
    \begin{scope}[very thick, color=Cyan]
        \draw (A top) parabola ++(-1,-1) -- (Cyan left anchor); %Left side
        \draw  (A top) parabola ++(1,-1) node(DeltaAux){} -- (Cyan right anchor) node[anchor=north east]{Cyan}; % Right side
    \end{scope}
    
    %- Orange line
    \begin{scope}[very thick, color=Orange]
        \draw (A top) parabola ++(-0.5,-1.75) -- (Orange left anchor);
        \draw  (A top) parabola ++(0.5,-1.75) -- (Orange right anchor) node[anchor=north east]{Orange};
    \end{scope}
    
    %- Delta
    \begin{scope}
        \draw[dashed] (A top) -- +(2,0) node(DeltaTop){};
        \draw[dashed] (DeltaAux) -- +(1,0) node(DeltaBottom){};
        \draw[<->] (DeltaBottom) -- (DeltaTop) node[rotate = 90,midway, below]{$\Delta$};           
    \end{scope}

    \end{tikzpicture}
    
\end{document}

答案1

好吧,我找到了方法。正如 J Leon V 所说,除非transform shape使用键,否则不会重新缩放节点,但这也会重新缩放文本。然而,这仅有的影响用声明的节点\node,但不是在路径/线的中间声明的节点。因此,我修改了代码,以便在创建图像上的线的同时声明我需要的节点。

现在它正常工作了。一切都缩放了,但文本仍然在它应该在的位置,并且保持它应该的大小。我在下面发布了修改,因此它可能可以为其他人提供参考 :)

\documentclass[IEEEtran]{standalone}
\usepackage{pgfplotstable} % Loads a bunch of packages
\pgfplotsset{compat=newest}
\usetikzlibrary{positioning}
\tikzstyle{help lines}=[thin,gray!40]
%- Define colors to be used 
\definecolor{Blue}{rgb}{0,0,1}%           
\definecolor{Cyan}{rgb}{0.0, 0.72, 0.92}%  
\definecolor{Orange}{rgb}{1.0, 0.49, 0.0}%    
\begin{document}
%
    \begin{tikzpicture}[scale=1, on grid]
    %- Axis node
    \node[inner sep=0,outer sep=0] (Origin Ax2) {};

    %- Blue line
    \node[inner sep=0,outer sep=0,right=0.25 of Origin Ax2] (Blue Begins) {}; %Origin node of blue rectangle
    %- Blue line + A node
    \begin{scope}[color=Blue,very thick]
        \draw (Blue Begins) -- ++(0,3) node[anchor=north west]{Blue}  -- ++(3.5,0) -- ++(0,-3) --++ (-3.5,0) node[below, midway] (A){ \color{black} A};
    \end{scope}
    %- Dashed line from A to top
    \begin{scope}[ dashed] % Line from (A) to (A top)
            \draw (A) -- ++(0,2.8) node[below,inner sep=0,outer sep=0] (A top) {};
    \end{scope}

    %- Axis
    \begin{scope}[-stealth,very thick]
        \draw (Origin Ax2)  -- +(0,3.5) node[anchor=south east,rotate=90] {Y axis}; % Y-axis
        \draw (Origin Ax2) -- +(4.75,0) node[anchor = north east]{X axis}; % X axis
    \end{scope}

%   %- Nodes to guide left and right side of the parabolas <- I think the problem might be here (?)
%   \node[inner sep=0,outer sep=0,above=1.25 of Blue Begins] (Cyan left anchor) {};
%   \node[inner sep=0,outer sep=0,right=3.5 of Cyan left anchor] (Cyan right anchor) {};
%   \node[inner sep=0,outer sep=0,above=0.5 of Blue Begins] (Orange left anchor) {};
%   \node[inner sep=0,outer sep=0,right=3.5 of Orange left anchor] (Orange right anchor) {};

    %- Cyan line
    \begin{scope}[very thick, color=Cyan]
        \draw (A top) parabola ++(-1,-1) -- ++(-0.75,0); %Left side
        \draw  (A top) parabola ++(1,-1) node(Cyan){} -- ++(0.75,0) node[midway,below]{Cyan}; % Right side
    \end{scope}

    %- Orange line
    \begin{scope}[very thick, color=Orange]
        \draw (A top) parabola ++(-0.5,-1.75) -- ++(-1.25,-0.5);
        \draw  (A top) parabola ++(0.5,-1.75) -- ++(1.25,-0.5) node[midway, below]{Orange};
    \end{scope}

    %- Delta
    \begin{scope}
        \draw[dashed] (A top) -- +(2,0) node(DeltaTop){};
        \draw[dashed] (Cyan) -- +(1,0) node(DeltaBottom){};
        \draw[<->] (DeltaBottom) -- (DeltaTop) node[rotate = 90,midway, below]{$\Delta$};           
    \end{scope}

    \end{tikzpicture}
    
\end{document}

相关内容