TikZ/pgfplots: 이와 같은 그림을 어떻게 생성할 수 있나요?

TikZ/pgfplots: 이와 같은 그림을 어떻게 생성할 수 있나요?

이와 같은 피규어를 만드는 가장 쉬운 방법은 무엇입니까? 곡선은 흔들리고 임의적으로 보이도록 되어 있으며 점프를 제외하면 항상 증가하지 않습니다. 무작위 단계로 장식을 사용해 보았지만 그게 제대로 보이지 않고 점점 늘어나는 경우도 있습니다. 또한 무작위로 생성한 많은 개별 좌표를 사용하여 플롯을 시도했지만 충분히 매끄럽게 보이지 않았습니다.

일반 TikZ 또는 pgfplot을 사용하게 되어 기쁩니다.

여기에 이미지 설명을 입력하세요

편집하다:여기에 두 가지 시도가 있습니다.

첫 번째는 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}  

여기에 이미지 설명을 입력하세요

두 번째 시도에서는 미세한 간격의 좌표가 많이 있는 pgfplot을 사용합니다(Excel에서 무작위로 생성했습니다). 이것은 더 가깝지만 너무 세밀하고 충분히 부드럽지 않습니다.

\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}

관련 정보