pgfplots: 다이어그램 상자의 둥근 모서리

pgfplots: 다이어그램 상자의 둥근 모서리

pgfplots이 MWE로 생성된 다음 이미지와 같이 외부 그리드가 직사각형인 작은 코드를 고려합니다 .

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

\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.15}
\begin{document}

\begin{tikzpicture}
\begin{axis}
\end{axis}
\end{tikzpicture}
\end{document}

하지만 이 직사각형 격자는 고정되어 있습니다. 아니면 모서리가 둥글고 색상이 지정되어 있고 둥근 직사각형 내에 다른 그래픽을 그릴 수 있는 이 이미지와 같은 이미지도 얻을 수 있습니까?

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

답변1

intersections이는 교차점에 대한 라이브러리 가 있는 일반 TikZ를 사용합니다 . 환경 은 scope중첩될 수 있으며 \clip채우기에는 여러 가 사용됩니다. 모서리가 더 둥근 직사각형을 원할 경우 [rounded corners=3mm]예를 들어 의 정의에서 간단히 사용하세요 \bb.

pgfplots나는 또한 환경에 적합한 옵션을 사용하면 쉽게 그릴 수 있다고 믿습니다 axis. 그러나 일반 TikZ는 나를 더 편안하게 만듭니다.

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

\documentclass[tikz,border=3mm]{standalone}
\usepackage{amsmath}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}[scale=2]
\def\bb{[rounded corners] (-1,-1) rectangle (2,1.5)}
\def\curveA{plot[domain=-1:2,smooth,samples=100]  (\x,{\x/(sqrt(1+\x*\x))})}
\def\curveB{plot[domain=-1:2,smooth,samples=100](\x,{pow(\x,4)-\x})}
\begin{scope} \clip \bb;
\begin{scope} 
\clip \curveA|-cycle;
\clip \curveB--cycle;
\fill[cyan!20] \bb;
\end{scope}
\draw (-1,0)--(2,0) (0,-1)--(0,1.5);
\draw[magenta,thick,name path=A] \curveA;
\draw[cyan,thick,name path=B] \curveB;
\path[name intersections={of=A and B}] (intersection-2) node[cyan,rectangle,minimum size=2mm,draw,thick]{};
\end{scope}
\draw[cyan] \bb;
\foreach \i in {-.5,0,...,1.5} \draw (\i,.05)--(\i,-.05);
\foreach \j in {-.5,0,...,1} \draw (.05,\j)--(-.05,\j);
\path
(-1,0) node[left]{$-1$}
(2,0) node[right]{$2$}
(0,-1) node[below]{$-1$}
(0,1.5) node[above]{$1.5$}
(1.2,-.5) node{$y=x^4-x$}
(.6,1.2) node (N) {$y=\dfrac{x}{\sqrt{x^2+1}}$};
\draw[-stealth] (N)--+(-60:.6);
\end{tikzpicture}
\end{document}

답변2

이 모든 작업은 간단한 pgfplots도구를 사용하여 수행할 수 있습니다.

  1. 둥근 프레임은 다음과 같이 간단합니다 axis background/.style={rounded corners=4mm,draw=blue}.
  2. 화살표를 제거하는 것은 다음과 같이 간단합니다 every inner x axis line/.append style={-},every inner y axis line/.append style={-}.
  3. 쉐이딩은 으로 할 수 있습니다 fillbetween.
  4. 공식은 간단한 라벨/핀입니다.
  5. xmin최대값과 최소값은 을 사용하여 등의 값을 기준으로 자동으로 첨부될 수 있습니다 after end axis/.code.

귀하의 편의를 위해 저는 이러한 것들을 대부분 이라는 스타일로 수집했습니다 Sebastiano.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\pgfplotsset{Sebastiano/.style={xticklabel=\empty,yticklabel=\empty,
    axis lines = center,
    every inner x axis line/.append style={-},
    every inner y axis line/.append style={-},
    axis background/.style={rounded corners=4mm,draw=blue},
    before end axis/.code={\path (0,0) coordinate (O);},
    after end axis/.code={
    \path
     (current axis.east|-O) node[right]
      {\pgfmathprintnumber{\pgfkeysvalueof{/pgfplots/xmax}}}
     (current axis.west|-O) node[left]
      {\pgfmathprintnumber{\pgfkeysvalueof{/pgfplots/xmin}}}
     (current axis.north-|O) node[above]
      {\pgfmathprintnumber{\pgfkeysvalueof{/pgfplots/ymax}}}
     (current axis.south-|O) node[below]
      {\pgfmathprintnumber{\pgfkeysvalueof{/pgfplots/ymin}}};
    }
}}
\usepgfplotslibrary{fillbetween}
\begin{document}

\begin{tikzpicture}
%
\begin{axis}[Sebastiano,width =12cm,
    xmin = -1,xmax = 2,
    ymin = -1,ymax = 1.5,
    domain=-1:2,smooth]
    \addplot[name path=A,color=magenta,thick]  {x/sqrt(1+x*x)}
    coordinate[pos=0.7,pin={[black,pin edge={stealth-,thick}]100:{$\displaystyle y=\frac{x}{\sqrt{1+x^2}}$}}](pA);
    \addplot[name path=B,color=cyan,thick]  {x^4-x}
    coordinate[pos=0.19,label={[black]below right:{$\displaystyle y=x^4-x$}}](pB);
    \addplot fill between [of=A and B,
        split,
        every segment no 0/.style={fill=none},
        every segment no 1/.style={cyan,opacity=50},
        every segment no 2/.style={fill=none},
        ];
\end{axis}
%
\end{tikzpicture}

\end{document}

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

답변3

시작점으로 Manuel Kuehner 박사의 답변을 사용합니다(더 간단한 다이어그램을 사용하기 때문에). TikZ 라이브러리 의 도움으로 fit:

\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{fit}
\pgfplotsset{compat=1.16}

\begin{document}
    \begin{tikzpicture}
\begin{axis}[name=PLOT,
    width = 80mm,
    height= 60mm,
    xmin = -1.2,
    xmax =  2.2,
    ymin = -1.3,
    ymax =  4.3,
    axis lines = center,
    scale only axis
    ]
    \addplot[
        domain = 0:2,
        red,
        line width = 1pt
        ]
        {x^2};
\coordinate (O) at (0,0);
\end{axis}
%
\node (f) [draw=blue, thick, rounded corners = 5mm, 
           inner sep=0pt, fit=(PLOT)] {};
\path   (O-|f.west)  node[lbl, left]  {$-1$}  (O-|f.east)  node[lbl,right] {$2$}
        (O|-f.north) node[lbl,above]  {$1.5$} (O|-f.south) node[lbl,below] {$-1$};
    \end{tikzpicture}
\end{document}

f편집: 노드 외부에 좌표 레이블을 추가했습니다 ( \Largered, 쉽게 볼 수 있고 그림에 있음, 이 설정은 쉽게 변경할 수 있음)

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

답변4

  • 단지 아이디어/시작(지금 잠자리에 들 것).
  • 두 개의 플롯을 서로의 위에 배치합니다.
  • 크기는 같지만 축 옵션이 다릅니다.
  • scale only axis중요하다.

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
%
\begin{axis}[
    width = 80mm,
    height = 60mm,
    xmin = -1.2,
    xmax = 2.2,
    ymin = -1.3,
    ymax = 4.3,
    axis x line = center,
    axis y line = center,
    %axis line style = {rounded corners = 4mm},
    scale only axis
    ]
    \addplot[
        domain = 0:2, 
        red, 
        line width = 1pt
        ] 
        {x^2};
\end{axis}
%
\begin{axis}[
    width = 80mm,
    height = 60mm,
    xmin = -1.2,
    xmax = 2.2,
    ymin = -1.3,
    ymax = 4.3,
    axis line style = {rounded corners = 5mm, blue},
    scale only axis,
    ticks = none
    ]
\end{axis}
%
\end{tikzpicture}

\end{document}

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

관련 정보