在论坛上找到了这个坐标平面,我非常喜欢它。我想要 4 个箭头,每个轴上 2 个,指向所有 4 个方向,而不是 2 个。不知道为什么箭头只指向右上方。我在许多笛卡尔平面上都见过这种情况。
短暂性脑缺血发作
以下是代码
\documentclass[tikz]{standalone}
\usepackage{tkz-euclide}
\begin{document}
\begin{figure}[h]
\begin{tikzpicture}
\tkzInit[xmax=6,ymax=6,xmin=-6,ymin=-6]
\tkzGrid
\tkzAxeXY
\draw[ thick,latex-latex] (-1,4) -- (4,-6) node[anchor=south west] {$a$}; % two points for drawing 2x+y=2
\tkzText[above](0,6.75){Desired Output}
\end{tikzpicture}
\end{figure}
\end{document}
pgfplots
坐标平面代码
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
axis line style={Stealth-Stealth, very thick},
xmin=-10,xmax=10,ymin=-10,ymax=10,
xtick distance=1,
ytick distance=1,
xlabel=$x$,
ylabel=$y$,
title={},
grid=major,
grid style={thick,black!50}]
\addplot [Latex-Latex,domain=-5:3,samples=2] {x*2/3} node[right]{$a$};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
我建议你改变距离规范
xtick distance=2,
ytick distance=2,
要更改刻度标签的字体,您可以使用:
xticklabel style={font=\small},
yticklabel style={font=\small},
代码:
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
axis line style={Stealth-Stealth, thick},
xmin=-10,xmax=10,ymin=-10,ymax=10,
xtick distance=2,
ytick distance=2,
xlabel=$x$,
ylabel=$y$,
xticklabel style={font=\small},
yticklabel style={font=\small},
title={},
grid=major,
grid style={thin,black!50}]
\addplot [Latex-Latex, red, thick, domain=-10:10,samples=2] {x*2/3} node[above left]{$a$};
\end{axis}
\end{tikzpicture}
\end{document}
答案2
\documentclass[tikz]{standalone}
\usepackage{tkz-base,tkz-euclide}
\begin{document}
\begin{tikzpicture}
\tkzInit[xmax=6,ymax=6,xmin=-6,ymin=-6]
\tkzGrid
\tikzset{xaxe style/.style = {> = latex, <->}
}
\tikzset{yaxe style/.style = {> = latex, < ->}
}
\tkzAxeXY
\tkzDefPoints{-1/4/A,4/-6/B}
\tkzDrawSegment[red,latex-latex](A,B)
\tkzText[above](0,6.75){Desired Output}
\end{tikzpicture}
\end{document}