目录
1 绘制坐标网格
1.1 代码
完整代码:
\documentclass[tikz,border=2mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[help lines,black] (0,0) grid (20,20); %网格线
\draw [->] (0,0)--(20.5,0) node[below right] { $X$};
\draw [->] (0,0)--(0,20.5) node[above left] {$Y$};
\node[below left] at (0,0) {0};
\foreach \i in {1,...,20}
\draw (\i,-0.05)--++(90:0.1) node[below=1mm]{\i};
\foreach \i in {1,...,20}
\draw (0.05,\i)--++(180:0.1) node[left=-0.5mm]{\i};
\end{tikzpicture}
\end{document}
代码效果:
1.2 代码注解
1.2.1 绘制坐标轴
\draw [->] (0,0)--(20.5,0) node[below right] { $X$};
注解:
- -> 表示绘制带箭头的坐标轴线
- node[below right] 在右下方标注 X
1.2.2 标注坐标原点
\node[below left] at (0,0) {0};
表示在(0,0)的左下角标注数字 0
1.2.3 标注坐标刻度
\foreach \i in {1,...,20} \draw (\i,-0.05)--++(90:0.1) node[below=1mm]{\i};
\foreach \i in {1,...,20} \draw (0.05,\i)--++(180:0.1) node[left=-0.5mm]{\i};
将坐标轴刻度数值标注到坐标轴上
还有一种枚举的方式:
% label the axis
\foreach \x in {0, 1, 2, 3, 4, 5,6,7,8,9,10} \draw (\x, 1pt) -- (\x, -1pt) node[anchor=north] {$\x$};
\foreach \y in {1, 2, 3, 4, 5,6,7,8,9,10} \draw (1pt, \y) -- (-1pt, \y) node[anchor=east] {$\y$};
1.2.4 绘制坐标格网线
% draw the grid
\draw[step=1cm, gray, ultra thin, dashed] (0,0) grid (10,10);
这里包含了四个参数:
- step:格网的步长
- gray:表示网线的颜色
- ultra thin:表示网线的粗细,还包括very thin; thick; very thick; ultra thick
- dashed:表示网线的线型,还包括dotted; loosely dashed; densely dashed等
2 在坐标轴上绘制信息
2.1 绘制线段
% draw the routes
\draw[red, ultra thick](2,2)--(6,6);
\draw[red, ultra thick](6,6)--(9,3);
代码表示的是使用红色粗线,绘制两条线段
2.2 为点增加编号
\draw (1.5,2) node[above]{$A$};
\draw (5.8,6) node[above]{$B$};
\draw (9.2,2.5) node[above]{$C$};
将A、B和C标注在坐标轴上
2.3 标记线长度
% label recourse length
\draw[black] (4,4) node[fill=white]{4$\sqrt[2]{2}$};
\draw[black] (7.5,4.5) node[fill=white]{3$\sqrt[2]{2}$};
3 参考资料
【LaTeX】TikZ官方手册笔记1:画坐标轴图 - 简书 (jianshu.com)https://www.jianshu.com/p/19ad8da765ce(2条消息) LaTeX - x,y坐标轴标签_weixin_34266504的博客-CSDN博客https://blog.csdn.net/weixin_34266504/article/details/92637422