pgfplot에 캡션 추가

pgfplot에 캡션 추가

로 만든 플롯에 캡션을 추가하려고 합니다 pgfplot. 코드는 다음과 같습니다:

\documentclass[border=20pt,tikz,varwith]{standalone}

\usepackage{pgfplots}
\pgfplotsset{
/pgfplots/xbar legend/.style={
    /pgfplots/legend image code/.code={%
        \draw[##1,/tikz/.cd,bar width=3pt,yshift=-0.2em,bar shift=0pt]
        plot coordinates {(0.8em,0cm)(0.6em,2*\pgfplotbarwidth)};}% <-changed
}
}


\usetikzlibrary{patterns}

\begin{document}
\begin{figure}
    \begin{tikzpicture}[scale=10]
    \begin{axis}[xbar,title style={xshift=-1.5cm},
    title=Figure 3..,
    enlargelimits=0.15,
    legend style={at={(1.3,.6)},
        anchor=north,reverse legend,legend cell align=left},
    yticklabels={Cat,Horse, Charly, Otto, Elisabeth, Fredy },
    xlabel={Happyness}]

    \addplot [draw=black,
    pattern=horizontal lines light blue,
    error bars/.cd,
    x dir=both,
    x explicit
    ] 
    coordinates {
        (10,5) -=(7,0) += (1,0) 
        (2,10) -=(2,0)  += (2,0) 
        (4,15)   -=(4,0) += (4,0)
        (5,20)   -=(5,0) += (5,0)
    };

    \addplot [draw=black,
    pattern=horizontal lines dark blue,
    error bars/.cd,
    x dir=both,
    x explicit
    ] 
    coordinates {
        (23,5)  -=(5,0) += (0.41-0.23,0) 
        (17,10)  -=(4,0) += (3,0) 
        (4,15)   -=(4,0) += (4,0) 
        (13,20)   -=(3,0) += (4,0) 
    }; 

    \legend{ Sweets, Playground}
    \draw[ultra thin] (axis cs:0,\pgfkeysvalueof{/pgfplots/ymin}) -- (axis cs:0,\pgfkeysvalueof{/pgfplots/ymax});
    \end{axis} 
    \end{tikzpicture}
    \caption{bla}
    \end{figure}
 \end{document}

불행히도 결과 출력은 세 페이지로 분할되어 출력의 한 페이지에 캡션이 있는 그림을 얻는 것이 아닙니다. 내가 무엇을 놓치고 있나요?

답변1

이 그림을 다른 곳에서 사용하는 경우 LaTeX가 아닌 거기에 캡션을 추가해야 합니다. 따라서 아마도 \begin{figure}, \caption{..}및 를 제거하고 싶을 \end{figure}것입니다.

\documentclass{standalone}
<preamble>
\begin{document}
\begin{tikzpicture}
<plot>
\end{tikzpicture}
\end{document}

[scale=10]그런데 꼭 제거해야 합니다 .

그러나 캡션이 필요하다고 주장하는 경우 tikz클래스에서 옵션을 제거하고 오타를 수정하고 패키지 varwidth를 추가하고 제목에서 알 수 있듯이 이것이 세 번째 그림이어야 하는 경우 capt-of추가하고 환경을 제거하고 다음을 사용하십시오 .\setcounter{figure}{2}figure\captionof{figure}{..}

\documentclass[border=20pt,varwidth]{standalone}

\usepackage{pgfplots,capt-of}
\pgfplotsset{
/pgfplots/xbar legend/.style={
    /pgfplots/legend image code/.code={%
        \draw[##1,/tikz/.cd,bar width=3pt,yshift=-0.2em,bar shift=0pt]
        plot coordinates {(0.8em,0cm)(0.6em,2*\pgfplotbarwidth)};}% <-changed
}
}


\usetikzlibrary{patterns}

\begin{document}

    \begin{tikzpicture}%[scale=10]
    \begin{axis}[xbar,title style={xshift=-1.5cm},
    title=Figure 3..,
    enlargelimits=0.15,
    legend style={at={(1.3,.6)},
        anchor=north,reverse legend,legend cell align=left},
    yticklabels={Cat,Horse, Charly, Otto, Elisabeth, Fredy },
    xlabel={Happyness}]

    \addplot [draw=black,
    pattern=horizontal lines light blue,
    error bars/.cd,
    x dir=both,
    x explicit
    ] 
    coordinates {
        (10,5) -=(7,0) += (1,0) 
        (2,10) -=(2,0)  += (2,0) 
        (4,15)   -=(4,0) += (4,0)
        (5,20)   -=(5,0) += (5,0)
    };

    \addplot [draw=black,
    pattern=horizontal lines dark blue,
    error bars/.cd,
    x dir=both,
    x explicit
    ] 
    coordinates {
        (23,5)  -=(5,0) += (0.41-0.23,0) 
        (17,10)  -=(4,0) += (3,0) 
        (4,15)   -=(4,0) += (4,0) 
        (13,20)   -=(3,0) += (4,0) 
    }; 

    \legend{ Sweets, Playground}
    \draw[ultra thin] (axis cs:0,\pgfkeysvalueof{/pgfplots/ymin}) -- (axis cs:0,\pgfkeysvalueof{/pgfplots/ymax});
    \end{axis} 
    \end{tikzpicture}
    \captionof{figure}{bla}

 \end{document}

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

관련 정보