pgfplot의 플롯과 "문서 크기" 사이의 1:1 비율을 얻으십시오.

pgfplot의 플롯과 "문서 크기" 사이의 1:1 비율을 얻으십시오.

나는 pgfplot의 플롯 길이를 예를 들어 플롯 외부의 tikz 좌표에서 얻는 것과 동일한 길이 비율을 얻으려고 했습니다.

예시로 사용하는 이미지는 다음과 같습니다.

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

\documentclass{standalone}
\usepackage{tikz,pgfplots}
\begin{document}
\begin{tikzpicture}

\draw[fill] (0,4.5) coordinate[label={right:\footnotesize{(0,4.5)}}] circle (0.06);
\draw[fill] (6,0) coordinate[label={above:\footnotesize{(6,0)}}] circle (0.06);
\begin{axis}[
  width=6cm,
  height=4.5cm,
  axis lines=middle,
  unit vector ratio=1 1,
  xmax=6,
  ymax=4.5,
  xmin=0,
  ymin=0,
  samples=50,
  xtick distance=1,ytick distance=0.5,
  every tick label/.append style={font=\tiny}
]
\addplot[domain=0:6] {1/\x^2};
\end{axis}

\end{tikzpicture}
\end{document}

축 길이와 "좌표 길이" 사이의 비율을 1:1로 만들고 싶지만 이를 관리하는 방법을 모르겠습니다.

감사해요.

답변1

[scale only axis]이 경우 화면 좌표와 일치하도록 너비와 높이를 수정하기 만 하면 됩니다 . 또는 옵션 [unit vector ratio][equal axis]중복됩니다.

\documentclass{standalone}
\usepackage{tikz,pgfplots}
\begin{document}
\begin{tikzpicture}

\draw[fill] (0,4.5) coordinate[label={right:\footnotesize{(0,4.5)}}] circle (0.06);
\draw[fill] (6,0) coordinate[label={above:\footnotesize{(6,0)}}] circle (0.06);
\begin{axis}[scale only axis,
  width=6cm,
  height=4.5cm,
  axis lines=middle,
  xmax=6,
  ymax=4.5,
  xmin=0,
  ymin=0,
  samples=50,
  xtick distance=1,ytick distance=0.5,
  every tick label/.append style={font=\tiny}
]
\addplot[domain=0:6] {1/\x^2};
\end{axis}

\end{tikzpicture}
\end{document}

데모

관련 정보