
pgfplotsの軸の制御に問題があります。グラフの環境を定義しました
\newenvironment{graph}[3][]{\begin{figure}[htp]
\def\tempa{#1} %Saves caption since \end cannot take arguments
\begin{center}
\begin{tikzpicture}[scale=1]
\draw node at (7,0) { \Large $ #2 $ }; %variable on x-axis
\draw node at (0,6.1) { \Large $ #3 $}; %variable on y-axis
\begin{axis}[
axis lines=left,
axis equal,
%ticks=none,
%xlabel=$x$,
%ylabel=$y$,
%width=8cm,
%height=8cm,
domain=0:10.5,
restrict y to domain=0:10.5
samples=1000
]
}
{
\end{axis}
\end{tikzpicture}
\end{center}
\ifdefempty{\tempa}{}{\caption{\tempa}} %Creates caption if argument is present.
\end{figure}
}
ご覧のとおり、軸について少し実験してみました。問題は、軸の長さが等しくないことです。軸を同じ固定ドメイン 0:10.5 にし、長さ (cm) を同じにしたいです。通常、y 軸は x 軸より短くなります。5 行目と 6 行目で軸の名前を定義します。ご覧のとおり、変数は軸の寸法として定義した 10.5 のような値ではなく、6.1 に配置されています。描画コマンドを使用するときに軸の座標を使用できるようにしたいと思います。
位置を 10 に設定すると、ノードが完全に間違った位置に配置されます。
\draw node at (10,0) { \Large $ #2 $ }; %variable on x-axis
最後の問題は、描画機能が環境内で動作しないことです。
\begin{graph}{x}{y}
\draw[dotted] (0,0) -- (2,2);
\end{graph}
これでは何も得られません:
前もって感謝します。
答え1
ここに提案があります。のunit vector ratio=1 1 1
代わりにを使用しました。これは、x 軸が少し拡張されるように見えるaxis equal
ためですが、理由はわかりません。軸ラベルは/ を使用して配置され、の場合と同様に、スタイルを変更することで位置が変更されます。座標は軸に対する相対座標であるため、たとえば はy 軸の上部にあることに注意してください。axis equal
xlabel
ylabel
every axis x label
y
(0,1)
(\caption
どこから来たのかわからないので\ifdefempty
、その部分は機能しないので削除しました。)
\draw
環境で と類似のものを使用する場合はgraph
、axis cs
以下の例に示すように、座標系を使用します。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\newenvironment{graph}[3][]{\begin{figure}[htp]
\centering
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
unit vector ratio=1 1 1,
every axis x label/.style={at={(1,0)},font=\Large,right},
every axis y label/.style={at={(0,1)},font=\Large,above},
xlabel=#2,
ylabel=#3,
domain=0:10.5,
xmin=0,xmax=10.5,
ymin=0,ymax=10.5,
samples=100,
no marks
]
}
{
\end{axis}
\end{tikzpicture}
\end{figure}
}
\begin{document}
\begin{graph}{$x$}{$y$}
\addplot {x};
\addplot {x+1};
\addplot {x-1};
\draw [dotted] (axis cs:0,10.5) -- (axis cs:10.5,10.5) -- (axis cs:10.5,0);
\end{graph}
\begin{graph}{$X$}{$Y$}
\addplot {8*sin(deg(x))*sin(deg(x))};
\draw [thick,latex-latex] (axis cs:1.57,8) to[out=40,in=140] node[above]{random} (axis cs:3.14+1.57,8);
\end{graph}
\end{document}