pgfplots 고정 너비의 그림

pgfplots 고정 너비의 그림

축 레이블 및 범례 항목을 포함하여 전체 치수가 설정된 독립형 pgfplots 그림을 어떻게 만들 수 있습니까?

pgfplots 로 플롯 크기를 설정하면 width=5cm, height=5cm,전체 수치만 제공됩니다.이 크기. 또한 범례가 축 상자 외부에 배치되면 범례 차원이 지정된 차원에 추가됩니다. 설명서에는 (4.10.1 일반적인 확장 옵션):

pgfplots는 축 및 눈금 레이블에 필요한 크기만 추정합니다. 추정에서는 축 상자 외부에 있는 모든 것에 대해 고정된 공간을 가정합니다. 이로 인해 최종 이미지가 규정된 치수보다 약간 더 크거나 약간 작을 수 있습니다.

그리고 더 나아가

scale only axis=false(기본값)이면 pgfplots는노력하다레이블, 제목 및 눈금을 포함하여 원하는 너비를 생성합니다.

내 MWE:

\documentclass[crop]{standalone}

\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}

\begin{axis}[
%Grouping
    scale only axis=false,
    height=,
    width=10cm,
%Domain
    xmin=2000, xmax=2020,
    ymode=log,
%Ticks
    /pgf/number format/1000 sep={},
%Axis Labels
    ylabel= Price \text{[}\$(2020)/kg\text{]},
%Legend
    legend cell align={left},
    legend pos=outer north east,
    legend style={draw=none},
    legend entries={Entry},
]
\addplot[draw=none] coordinates {(2005,10000)};
\end{axis}

\end{tikzpicture}
\end{document}

다음은 게시한 솔루션의 시각적 표현입니다.존 코밀로:

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

답변1

보기에는 끔찍해 보이지만 5cm x 5cm 직사각형에 정확히 들어맞습니다.

데모

\documentclass[crop]{standalone}

\usepackage[utf8]{inputenc}
\usepackage{tikz}% reducndant
\usepackage{pgfplots}

\newsavebox{\temp}

\begin{document}
\savebox{\temp}{\begin{tikzpicture}

\begin{axis}[
%Grouping
    name=border,
    height=5cm,
    width=5cm,
%Domain
    xmin=2000, xmax=2020,
    ymode=log,
%Ticks
    /pgf/number format/1000 sep={},
%Axis Labels
    ylabel= Price \lbrack\$(2020)/kg\rbrack,
%Legend
    legend cell align={left},
    legend pos=outer north east,
    legend style={draw=none},
    legend entries={Entry},
]
\addplot[draw=none] coordinates {(2005,10000)};
\end{axis}

\end{tikzpicture}}% trial

\begin{tikzpicture}

\begin{axis}[
%Grouping
    name=border,
    height={\dimexpr 10cm-\ht\temp},
    width={\dimexpr 10cm-\wd\temp},
%Domain
    xmin=2000, xmax=2020,
    ymode=log,
%Ticks
    /pgf/number format/1000 sep={},
%Axis Labels
    ylabel= Price \lbrack\$(2020)/kg\rbrack,
%Legend
    legend cell align={left},
    legend pos=outer north east,
    legend style={draw=none},
    legend entries={Entry},
]
\addplot[draw=none] coordinates {(2005,10000)};
\end{axis}
\draw[red] (current bounding box.south west) rectangle (current bounding box.north east);
\draw[green] (current bounding box.south west) rectangle ++(5cm,5cm);

\end{tikzpicture}

\end{document}

관련 정보