TikZ/pgfplots: このような図を生成するにはどうすればよいでしょうか?

TikZ/pgfplots: このような図を生成するにはどうすればよいでしょうか?

このような図を作成する最も簡単な方法は何ですか? 曲線は、波打ってランダムに見えるようにし、ジャンプを除いて常に非増加になるようにします。ランダムなステップの装飾を使用してみましたが、見た目が適切ではなく、時々増加しています。ランダムに生成した多数の個別の座標を含むプロットも試しましたが、十分に滑らかに見えませんでした。

プレーンな TikZ または pgfplots のどちらでも使用できます。

ここに画像の説明を入力してください

編集:ここに2つの試みがあります。

最初のものはrandom steps装飾を使用していますが、プロットは滑らかではなく、時々増加しています。いくつかの異なる振幅を試しました。

\documentclass{standalone}

\usepackage{tikz}
\pgfplotsset{compat=1.10}

\begin{document}

    \begin{tikzpicture}

        \draw[->] (0,0) -- (10,0);
        \draw[->] (0,0) -- (0,5);

        \draw [decorate, decoration={random steps,amplitude=2pt}] (0.2,4) -- (3,1);
        \draw (3,1) -- (3,5);
        \draw [decorate, decoration={random steps,amplitude=5pt}] (3,5) -- (5,0.2);
        \draw (5,0.2) -- (5,3);
        \draw [decorate, decoration={random steps,amplitude=8pt}] (5,3) -- (8,1.5);
        \draw (8,1.5) -- (8,4);
        \draw [decorate, decoration={random steps,amplitude=5pt}] (8,4) -- (9,3.5);

        \useasboundingbox (-1,-1) rectangle (11,6);

    \end{tikzpicture}

\end{document}  

ここに画像の説明を入力してください

2 番目の試みでは、細かく間隔を空けた座標 (Excel でランダムに生成したもの) を多数含む pgfplots を使用します。こちらの方が近いですが、粒度が細かすぎて滑らかさが足りません。

\documentclass{standalone}

\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}

\begin{document}

    \begin{tikzpicture}

        \begin{axis} [
            axis lines=left,
            xtick=\empty,
            ytick=\empty,
        ]

        \addplot [mark size=0]
            coordinates {
                (0.2,4)
                (0.245550438070978,3.9189299356319)
                (0.309894093387146,3.8555584914932)
                (0.374626991695131,3.77679077960278)
                (0.380585874068229,3.74823005668191)
                ... you get the idea ...                
                (11.2737449020538,2.23155401800146)
                (11.2994722948852,2.22522905911657)
                (11.3669785475168,2.17668213475497)
        };

        \end{axis}

    \end{tikzpicture}

\end{document}  

ここに画像の説明を入力してください

答え1

まずは装飾を見てみましょうrandom step

\documentclass[border=9,tikz]{standalone}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\makeatletter



\tikzset{
    demo decoration/.style={
        gray,
        postaction={draw=red,decorate,decoration={segment length=6pt,amplitude=3pt,meta-amplitude=12pt,#1}}
    }
}
\begin{tikzpicture}[remember picture]
    \path(0,0)node(A){}(6,0)node(B){};
    \draw[demo decoration=random steps](A)to[bend left](B);
\end{tikzpicture}

できます滑らかにするそれを で\pgfsetcornersarced作りました。そこで という装飾を作りましたrandom drift

\pgfdeclaredecoration{random drift}{start}
{
  \state{start}[width=+0pt,next state=step,persistent precomputation=\pgfdecoratepathhascornerstrue]
  {
    \egroup
    \pgfsetcornersarced{\pgfqpoint{.2\pgfdecorationsegmentlength}{.2\pgfdecorationsegmentlength}}
    \bgroup
  }
  \state{step}[width=+\pgfdecorationsegmentlength]
  {
    \pgfpathlineto{
      \pgfpointadd
      {\pgfqpoint{\pgfdecorationsegmentlength}{0pt}}
      {\pgfpoint{rand*\pgfdecorationsegmentamplitude}{rand*\pgfdecorationsegmentamplitude}}
    }
  }
  \state{final}
  {}
}
\begin{tikzpicture}
    \draw[demo decoration=random drift](A)to[bend left](B);
\end{tikzpicture}

そして、私はいくつか追加します飛び上がるここでは、\pgf@randomsaw@yy 座標を保存し、それに負のランダムな長さを追加して、関数が増加しないようにします。

\pgfdeclaredecoration{random saw}{start}
{
  \state{start}[width=+0pt,next state=step,persistent precomputation=\pgfdecoratepathhascornerstrue]
  {
    \egroup
    \pgfsetcornersarced{\pgfqpoint{.2\pgfdecorationsegmentlength}{.2\pgfdecorationsegmentlength}}
    \bgroup
    \newdimen\pgf@randomsaw@y
  }
  \state{step}[width=+\pgfdecorationsegmentlength]
  {
    \pgfmathsetlength\pgf@ya{-rnd*\pgfmetadecorationsegmentamplitude}
    \pgfmathsetlength\pgf@yb{ rnd*\pgfmetadecorationsegmentamplitude}
    \ifdim\pgf@randomsaw@y<\pgf@ya
      \pgfsetcornersarced{\pgfqpoint{0pt}{0pt}}
      \pgfpathlineto{\pgfpoint{\pgfdecorationsegmentlength}{\pgf@randomsaw@y-4*rnd*\pgfdecorationsegmentamplitude}}
      \pgfpathlineto{\pgfqpoint{\pgfdecorationsegmentlength}{\pgf@yb}}
      \global\pgf@randomsaw@y\pgf@yb
    \else
      \pgfmathsetlength\pgf@xa{\pgfdecorationsegmentlength+rand*\pgfdecorationsegmentamplitude}
      \pgfmathsetlength\pgf@ya{\pgf@randomsaw@y-4*rnd*\pgfdecorationsegmentamplitude}
      \pgfpathlineto{\pgfqpoint{\pgf@xa}{\pgf@ya}}
      \global\pgf@randomsaw@y\pgf@ya
    \fi
  }
  \state{final}
  {}
}
\begin{tikzpicture}
    \draw[demo decoration={random saw,segment length=4pt,amplitude=2pt,meta-amplitude=20pt}](A)to[bend left](B);
\end{tikzpicture}



\end{document}

関連情報