たとえば、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}