
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
여기에 제안이 있습니다. 대신 x축이 약간 확장되는 것 같아서 대신 사용했는데 이유는 unit vector ratio=1 1 1
모르겠습니다 . 축 레이블은 / 를 사용하여 배치되고 위치 는 와 유사하게 스타일을 변경하여 수정됩니다 . 좌표는 축을 기준으로 합니다. 예를 들어 y축의 상단에 있습니다.axis equal
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}