곡선과 축이 그려지기 전에 pgfplots 축 환경에 임의 코드 추가

곡선과 축이 그려지기 전에 pgfplots 축 환경에 임의 코드 추가

내가 정말로 원하는 것이 무엇인지에 대해 약간의 혼란이 있었기 때문에 여기에 실제 사용 사례를 포함시켰습니다. MWE plus 해당 사진은 게시물 하단에 있습니다.

나는 사용자 정의 그리드 선을 사용하는 멋진 그래프를 만들었습니다. 일부 그리드 선은 사용자 정의된 축까지 가지 않습니다. 그 일을 완수하기 위해 내가 할 수 있는 최선의 방법은 무엇입니까?

http://i.imgur.com/kIU9gjT.png

\documentclass{standalone}
\usepackage{pgf}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\usepackage{tikz}
\usetikzlibrary{arrows,calc,shapes, positioning}
\tikzset{
  shadowed/.style={preaction={
      transform canvas={shift={(2pt,-1pt)}},draw opacity=.2,#1,preaction={
        transform canvas={shift={(4pt,-1.75pt)}},draw opacity=.1,#1,preaction={
          transform canvas={shift={(6pt,-2.5pt)}},draw opacity=.05,#1,preaction={
          transform canvas={shift={(8pt,-3.25pt)}},draw opacity=.025,#1,
        }
        }}}},
}
\makeatletter
\def\pgfplotsdataxmin{\pgfplots@data@xmin}
\def\pgfplotsdataxmax{\pgfplots@data@xmax}
\def\pgfplotsdataymin{\pgfplots@data@ymin}
\def\pgfplotsdataymax{\pgfplots@data@ymax}
\makeatother
\pgfplotsset{
    range frame/.style={
        tick align=outside,
        axis line style={opacity=0},
        after end axis/.code={
            \draw[cyan,thick,double=white,double distance=1.4pt,line cap=round,rounded corners] ({rel axis cs:0,0}-|{axis cs:\pgfplotsdataxmax,0}) -- ({rel axis cs:0,0}-|{axis cs:\pgfplotsdataxmin,0}) --   ({rel axis cs:0,0}|-{axis cs:0,\pgfplotsdataymin}) -- ({rel axis cs:-.1,0}|-{axis cs:0,\pgfplotsdataymax});
        }
    }
}

\begin{document}
\begin{tikzpicture}[scale=2]
\begin{axis}[range frame,
        domain=25.29325198:97,
        axis lines*=left,
        yticklabel=\empty,
        xticklabels=\empty,
        xtick style={draw=none},
        ytick style={draw=none},
extra description/.code={%
\node[] at (axis cs:6,60) {$60$};
\node[] at (axis cs:8.6,40) {$40$};
\node[] at (axis cs:11.5,20) {$20$};
\node[] at (axis cs:15,0) {$0$};
\node[] at (axis cs:25,-11.3) {$25$};
\node[] at (axis cs:50,-11.3) {$50$};
\node[] at (axis cs:75,-11.3) {$75$};
\draw[ultra thin,lightgray] (axis cs:25,-9) -- (axis cs:25,-7);
\draw[ultra thin,lightgray] (axis cs:50,-9) -- (axis cs:50,-7.5);
\draw[ultra thin,lightgray] (axis cs:75,-9) -- (axis cs:75,-7.5);
\node[] at (axis cs:\pgfplotsdataxmin-15.5,\pgfplotsdataymax+4.4) {$m_\mathrm{gr}$};
\node[] at (axis cs:\pgfplotsdataxmax+5.5,\pgfplotsdataymin-7) {$m_\mathrm{f}$};
}
]
\draw[ultra thin,lightgray] (axis cs:-8.05,20) -- (axis cs:\pgfplotsdataxmax,20);
\draw[ultra thin,lightgray] (axis cs:-8.05,0) -- (axis cs:\pgfplotsdataxmax,0);
\draw[ultra thin,lightgray] (axis cs:-8.05,40) -- (axis cs:\pgfplotsdataxmax,40);
\draw[ultra thin,lightgray] (axis cs:-8.05,60) -- (axis cs:\pgfplotsdataxmax,60);
\addplot[shadowed={double=gray,draw=gray},thick,line cap=round,rounded corners, draw=purple,double=white,double distance=1.6pt,
]  {-23.73194+0.9382716*x};
\end{axis}
\end{tikzpicture}
\makeatother


\end{document}

원래 게시물:강제로 나만의 그리드 선을 생성해야 하는데 아래 코드를 사용하면 축이 그리드 선과 겹칩니다. 이로 인해 그리드 선의 일부가 무시됩니다. 나는 그것들을 축 바로 뒤에 그리고 내가 지정한 x 좌표를 따르고 싶습니다. 축과 곡선이 그려지기 전에 선을 그릴 수 있지만 축으로 인해 공백이 겹치지 않게 하려면 어떻게 해야 합니까?

http://i.imgur.com/8c8YjMh.png

\documentclass{standalone}
\usepackage{pgfplots}
\makeatletter
\begin{document}
\begin{tikzpicture}[scale=2]
\begin{axis}[
extra description/.code={%preaction={ %preaction doesn't work
},%}
]
\draw[ultra thick,lightgray] (axis cs:-2,2) -- (axis cs:\pgfplots@data@xmax,2);
\draw[ultra thick,lightgray] (axis cs:.04,4) -- (axis cs:\pgfplots@data@xmax,4);
\draw[ultra thick,lightgray] (axis cs:0,6) -- (axis cs:\pgfplots@data@xmax,6);
\addplot[
] table {
dof l2_err level
.2 2.6 2
.4 2.3 4
.5 2.4 5
.6 1.1 6
.7 1.8 7
.8 4.6 8
.9 3.3 9
1 6.2 10
};
\end{axis}
\end{tikzpicture}
\makeatother
\end{document}

답변1

execute at <begin/end> <certain events>보다 일관된 출력을 위해 키를 사용할 수 있습니다 . 또한 최대 데이터 포인트 대신 axis description cs데이터 포인트의 위치와 관계없이 전체 축 길이를 얻는 데 사용할 수 있습니다.

\documentclass{standalone}
\usepackage{pgfplots}
\makeatletter
\pgfplotsset{compat=1.11,
my extras/.style={
  execute at begin axis={
    \draw[ultra thick,lightgray] (axis cs:.08,2) -- (axis cs:\pgfplots@data@xmax,2);
    \draw[ultra thick,lightgray] (axis cs:.04,4) -- (axis cs:\pgfplots@data@xmax,4);
    \draw[ultra thick,lightgray] (axis cs:0,6) -- (axis cs:\pgfplots@data@xmax,6);
    }
  }
}
\makeatother
\begin{document}
\begin{tikzpicture}[scale=2]
\begin{axis}[my extras]
\addplot+[ultra thick,
] table {
dof l2_err level
.2 2.6 2
.4 2.3 4
.5 2.4 5
.6 1.1 6
.7 1.8 7
.8 4.6 8
.9 3.3 9
1 6.2 10
};
\end{axis}
\end{tikzpicture}
\end{document}

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

답변2

업데이트 된 질문의 해결책이 추가되는 것 같습니다.

clip=false,

환경에 axis. 귀하의 버전에서는 수동 수평 격자선이 축의 원래 크기를 벗어나 잘립니다.

그런 다음 수평선의 끝 부분도 조정해야 합니다. 예:

\draw[ultra thin,lightgray] (axis cs:17,0) -- (axis cs:\pgfplotsdataxmax,0);
\draw[ultra thin,lightgray] (axis cs:14.3,20) -- (axis cs:\pgfplotsdataxmax,20);
\draw[ultra thin,lightgray] (axis cs:11.6,40) -- (axis cs:\pgfplotsdataxmax,40);
\draw[ultra thin,lightgray] (axis cs:9,60) -- (axis cs:\pgfplotsdataxmax,60);

thin더 나은 가시성을 위해 이 미리보기에서 선 너비를 다음과 같이 변경했습니다 .시사

관련 정보