pgfplots를 사용하여 멋진 "프록시" 범례 선을 어떻게 그릴 수 있나요?

pgfplots를 사용하여 멋진 "프록시" 범례 선을 어떻게 그릴 수 있나요?

축에 그리는 두 개의 곡선이 있는데 그 중 하나는 "멋진" 선으로 그려진 원입니다(두꺼운 검은색 곡선을 약간 더 얇은 흰색 점선 곡선으로 오버레이합니다). 일치하는 범례 항목을 위조할 수 있는 방법이 있습니까?

나는 pgfplots 매뉴얼을 보았고 보았지만 \addlegendimage기본적인 \addlegendentry간단한 라인을 제외하고는 그것을 사용하는 방법을 생각할 수 없습니다:

\documentclass[tikz, border=2mm]{standalone}
\usepackage{pgfplots}
\usepackage{sansmath}
\pgfplotsset{compat=1.17}
% pgfplots package manual at https://ctan.org/pkg/pgfplots?lang=en
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    axis equal,
    width=10cm, height=6cm,
    font=\sffamily,
    ticklabel style = {font=\sansmath\sffamily},
    xmin=-0.7,xmax=0, xlabel={$x$}, xtick={-1,-0.9,...,0}, minor xtick={-1,-0.95,...,0}, 
    ymin=0.7,ymax=1.0, ylabel={$y$}, ytick={0, 0.1,...,1}, minor ytick={0, 0.05,...,1},
    samples=500,domain=-1:0,
    grid=both,
    legend pos = south east,
    legend cell align = left,
    title={\large shapes on axis}]
        
  % I want to add a legend saying "circle"
  \draw [black, line width = 0.7mm] (0,0) circle [radius=1.0];
  \draw [white, line width = 0.5mm, dash pattern = on 5pt off 5pt] (0,0) circle [radius=1.0];
  \addlegendimage{black, line width=0.7mm};
  
  \addplot[blue, line width = 0.3mm]({x}, {1-0.5*x*x} ); 
  
  
  % I want to add a legend saying "line"
  \draw [green!50!black, line width=0.3mm] (-0.6,1) -- (-0.4,0.95);
  \addlegendimage{green!50!black, line width=0.3mm};
  
  \legend {circle, quadratic curve, line};
  

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

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

원 범례에 동일한 선 패턴을 갖도록 하려면 어떻게 해야 합니까?

답변1

옵션 postaction(또는 preaction)을 사용하면 두 \draws를 하나로 병합할 수 있습니다. 이 두 가지 옵션은 pgfmanual, sec에 설명되어 있습니다. 15.10경로에서 여러 작업 수행v3.1.5b에서.

비슷하다이 답변, is를 사용한 예 ( 에서 사용된 postaction옵션 참고 )drawpostactions={...}

\documentclass[tikz, border=2mm]{standalone}

\begin{document}
\begin{tikzpicture}
  \draw
      [postaction={draw, white, dash pattern=on 4pt off 4pt, dash phase=4pt, thick}]
      [black, ultra thick] 
      (0,0) rectangle (3,2);
\end{tikzpicture}
\end{document}

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

모든 옵션을 새로운 스타일로 래핑하면 double colors다음과 같이 예제를 그릴 수 있습니다( dash phase=-4pt에 추가됨 참고 \addlegendimage[...]).

\documentclass[tikz, border=2mm]{standalone}
\usepackage{pgfplots}
\usepackage{sansmath}
\pgfplotsset{compat=1.17}

\tikzset{
  double colors/.style={
    postaction={draw, white, line width = 0.5mm, dash pattern = on 5pt off 5pt},
    black, line width = 0.7mm
  }
}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    axis equal,
    width=10cm, height=6cm,
    font=\sffamily,
    ticklabel style = {font=\sansmath\sffamily},
    xmin=-0.7,xmax=0, xlabel={$x$}, xtick={-1,-0.9,...,0}, minor xtick={-1,-0.95,...,0}, 
    ymin=0.7,ymax=1.0, ylabel={$y$}, ytick={0, 0.1,...,1}, minor ytick={0, 0.05,...,1},
    samples=500,domain=-1:0,
    grid=both,
    legend pos = south east,
    legend cell align = left,
    title={\large shapes on axis}]
        
  % I want to add a legend saying "circle"
  \draw [double colors] (0,0) circle [radius=1.0];
  \addlegendimage{double colors, dash phase=-4pt, line width=0.7mm};
  
  \addplot[blue, line width = 0.3mm]({x}, {1-0.5*x*x} ); 
  
  % I want to add a legend saying "line"
  \draw [green!50!black, line width=0.3mm] (-0.6,1) -- (-0.4,0.95);
  \addlegendimage{green!50!black, line width=0.3mm};
  
  \legend {circle, quadratic curve, line};
  
\end{axis}
\end{tikzpicture}

\end{document}

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

관련 정보