错误

错误

我在 TikZ 中箭头的“向左弯曲=...”选项上遇到了一个奇怪的问题,我似乎找不到现有的解决方案。

編輯:

基本上我想创建这种图表。也就是说,红色和蓝色箭头都相对于连接每个圆弧的两个点向上弯曲(90 度)。

在此处输入图片描述

我为此创建了自己的命令 \myarrows,因为我想要制作大量具有可变长度(弧数)和偏移量的此类命令。我的想法是,如果请求的循环数为负数(第一个参数),则循环将沿相反方向(向左)绘制。在这种情况下,我应该简单地将弯曲角度乘以第一个参数(循环数)的符号。然而,这似乎不起作用。我在这里做错了什么?请注意,如果我直接在代码中指定角度(注释掉),它就可以正常工作。

\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{calc} 
\pgfplotsset{compat=newest}

\pgfplotsset{ /pgf/declare function={
    logkn(\n)   = log10(1.3^\n);
    N           = 120;
    dN          = 12;
    sgn(\x)     = \x/abs(\x);
    y(\n)       = 1.07^\n * 5e-2;
}}

\pgfplotsset{xlabel=$\log x$, ylabel=$\log y$,ytick=\empty,xtick=\empty,axis lines=left,xmin=logkn(1),xmax=logkn(N), domain=1:N,samples=1e2}

\newcommand{\myarrows}[3]{  % \myarrows{NUMBER OF LOOPS -1}{XAXIS OFFSET}{COLOR}

    \pgfplotsinvokeforeach{0,...,#1}{ 

        % CORRECTLY BENDS IN ONE DIRECTION
%       \draw[mystyle,#3] (axis cs:{logkn( #2+dN*##1 )}, {y( #2+dN*##1 )}) to [bend left=+90.0, distance=0.5cm] ( axis cs: {logkn( #2+dN*(##1+sgn(#1)) )}, {y( #2+dN*(##1+sgn(#1)) )});
        % CORRECTLY BENDS IN OTHER DIRECTION
%       \draw[mystyle,#3] (axis cs:{logkn( #2+dN*##1 )}, {y( #2+dN*##1 )}) to [bend left=-90.0, distance=0.5cm] ( axis cs: {logkn( #2+dN*(##1+sgn(#1)) )}, {y( #2+dN*(##1+sgn(#1)) )});
        % MY ATTEMPT TO GENERALIZE USING THE SIGN OF #1 -- DOES NOT WORK
        \draw[mystyle,#3] (axis cs:{logkn( #2+dN*##1 )}, {y( #2+dN*##1 )}) to [bend left={90*sgn(#1)}, distance=0.5cm] ( axis cs: {logkn( #2+dN*(##1+sgn(#1)) )}, {y( #2+dN*(##1+sgn(#1)) )});
    }       
    \node[] at ({logkn(#2+dN*#1)},1e-1) {\scriptsize bend left$=\pgfmathparse{90*sgn(#1)}\pgfmathresult$};
}

\begin{document}
\begin{tikzpicture}[scale=2, mystyle/.style={thick,->,black}]
\begin{semilogyaxis}[ymin=1e-2,ymax=1e2]
        \myarrows{2}{60}{blue}  % {NUMBER OF LOOPS -1}{XAXIS OFFSET}{COLOR}
        \myarrows{-2}{60}{red}  % {NUMBER OF LOOPS -1}{XAXIS OFFSET}{COLOR}
\end{semilogyaxis}
\end{tikzpicture}
\end{document}

产生

在此处输入图片描述

谢谢你!

答案1

(此错误自 pgf/TikZ 3.1 版起已修复。)

错误

这是bend left():

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
  \draw [red,->] (0,0) to[bend left=90*-1] (1,0);
\end{tikzpicture}
\end{document}

在此处输入图片描述

编辑答案

使用inoutrelative

\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{calc} 
\pgfplotsset{compat=newest}

\pgfplotsset{ /pgf/declare function={
    logkn(\n)   = log10(1.3^\n);
    N           = 120;
    dN          = 12;
    sgn(\x)     = \x/abs(\x);
    y(\n)       = 1.07^\n * 5e-2;
}}

\pgfplotsset{xlabel=$\log x$, ylabel=$\log y$,ytick=\empty,xtick=\empty,axis lines=left,xmin=logkn(1),xmax=logkn(N), domain=1:N,samples=1e2}

\newcommand{\myarrows}[3]{  % \myarrows{NUMBER OF LOOPS -1}{XAXIS OFFSET}{COLOR}

  \pgfplotsinvokeforeach{0,...,#1}{ 
    \draw[mystyle,#3] (axis cs:{logkn( #2+dN*##1 )}, {y( #2+dN*##1 )}) to [out=90*sgn(#1),in=90*sgn(#1),relative, distance=0.5cm] ( axis cs: {logkn( #2+dN*(##1+sgn(#1)) )}, {y( #2+dN*(##1+sgn(#1)) )});
  }       
  \node[] at ({logkn(#2+dN*#1)},1e-1) {\scriptsize bend left$=\pgfmathparse{90*sgn(#1)}\pgfmathresult$};
}

  \begin{document}
\begin{tikzpicture}[scale=2, mystyle/.style={thick,->,black}]
\begin{semilogyaxis}[ymin=1e-2,ymax=1e2]
        \myarrows{2}{60}{blue}  % {NUMBER OF LOOPS -1}{XAXIS OFFSET}{COLOR}
        \myarrows{-2}{60}{red}  % {NUMBER OF LOOPS -1}{XAXIS OFFSET}{COLOR}
\end{semilogyaxis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

第一个答案

不要bend left随意使用out=90,in=90

\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{calc} 
\pgfplotsset{compat=newest}

\pgfplotsset{ /pgf/declare function={
    logkn(\n)   = log10(1.3^\n);
    N           = 120;
    dN          = 12;
    sgn(\x)     = (\x/abs(\x));
  }}

\pgfplotsset{xlabel=$\log x$, ylabel=$\log y$,ytick=\empty,xtick=\empty,axis lines=left,xmin=logkn(1),xmax=logkn(N), domain=1:N,samples=1e2}

\newcommand{\myarrows}[3]{  % \myarrows{NUMBER OF LOOPS -1}{XAXIS OFFSET}{COLOR}
  \pgfplotsinvokeforeach{0,...,#1}{ 
    \draw[mystyle,#3]
    (axis cs:{logkn(#2+dN*##1},1e0)
    to [out=90, in=90, distance=0.5cm]
    ( axis cs:{logkn(#2+dN*(##1+sgn(#1)))}, 1e0);
  }

  \node[] at ({logkn(#2+dN*#1)},1e-1) {\scriptsize bend left$=\pgfmathparse{90*sgn(#1)}\pgfmathresult$};
}

\begin{document}
\begin{tikzpicture}[scale=2, mystyle/.style={thick,->,black}]
  \begin{semilogyaxis}[ymin=1e-2,ymax=1e2]
    \myarrows{2}{60}{blue}  % {NUMBER OF LOOPS -1}{XAXIS OFFSET}{COLOR}
    \myarrows{-2}{60}{red}  % {NUMBER OF LOOPS -1}{XAXIS OFFSET}{COLOR}
  \end{semilogyaxis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

你想要这样的东西吗?

表现更好的弧

我不确定为什么您的代码不起作用,但下面的代码可以。

\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{calc}
\pgfplotsset{compat=newest}

\pgfplotsset{ /pgf/declare function={
    logkn(\n)   = log10(1.3^\n);
    N           = 120;
    dN          = 12;
    sgn(\x)     = \x/abs(\x);
}}

\pgfplotsset{xlabel=$\log x$, ylabel=$\log y$,ytick=\empty,xtick=\empty,axis lines=left,xmin=logkn(1),xmax=logkn(N), domain=1:N,samples=1e2}

\newcommand{\myarrows}[3]{% \myarrows{NUMBER OF LOOPS -1}{XAXIS OFFSET}{COLOR}
  \pgfplotsinvokeforeach{0,...,#1}{
    \pgfmathsetmacro\mysgn{90*sgn(#1)}%
%     \draw [mystyle,#3,green] (axis cs:{logkn(#2+dN*##1},1e0) to [bend left=+90.0, distance=0.5cm] ( axis cs:{logkn(#2+dN*(##1+sgn(#1)))}, 1e0); % Works correctly for #1 > 0
%     \draw [mystyle,#3,orange] (axis cs:{logkn(#2+dN*##1},1e0) to [bend left=-90.0, distance=0.5cm] ( axis cs:{logkn(#2+dN*(##1+sgn(#1)))}, 1e0); % Works correctly for #1 < 0
    \draw [mystyle,#3] (axis cs:{logkn(#2+dN*##1},1e0) to [bend left=\mysgn, distance=0.5cm] ( axis cs:{logkn(#2+dN*(##1+sgn(#1)))}, 1e0);  % Does not work. How come?
  }
  \node[] at ({logkn(#2+dN*#1)},1e-1) {\scriptsize bend left$=\pgfmathparse{90*sgn(#1)}\pgfmathresult$};
}

\begin{document}
\begin{tikzpicture}[scale=2, mystyle/.style={thick,->,black}]
  \begin{semilogyaxis}[ymin=1e-2,ymax=1e2]
    \myarrows{2}{60}{blue}  % {NUMBER OF LOOPS -1}{XAXIS OFFSET}{COLOR}
    \myarrows{-2}{60}{red}  % {NUMBER OF LOOPS -1}{XAXIS OFFSET}{COLOR}
  \end{semilogyaxis}
\end{tikzpicture}
\end{document}

如果这没有帮助的话请告诉我,我将删除它。

相关内容