欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

1.TikZ 绘图坐标系

最编程 2024-03-31 07:53:01
...

1 绘制步骤

  • 画两条坐标轴
  • 添加坐标轴名称
  • 添加原点
  • 画刻度

2 绘制过程

\documentclass[10pt]{standalone}
\usepackage{tikz} 
\begin{document}
\begin{tikzpicture}
%画x和y轴坐标
\draw[->] (-5.2,0)--(5.2,0);
\draw[->] (0,-5.2)--(0,5.2);
%画刻度
\foreach \x in {0,1,...,8}
{
    \draw[xshift=\x cm] (-4,0) -- (-4,0.1);
    \draw[yshift=\x cm] (0,-4) -- (0.1,-4);
};  
%标坐标原点
\node[below] at (0.2,0){0};
%标x轴刻度值
\foreach \x in {-4,-3,...,-1}
    \node[below] at(\x,0){\x};
\foreach \y in {1,2,...,4}
    \node[below] at(\y,0){\y};
% 标注y轴刻度
\foreach \y in {-4,-3,...,-1}
    \node[left] at(0,\y){\y};
\foreach \y in {1,2,...,4}
    \node[left] at(0,\y){\y};
\end{tikzpicture}
\end{document}

3 结果

4 知识点

  • foreach循环
for \x in {1,2,...,4}{
执行语句;
};

for 句子结尾要用分号。

  • 直线平移命令
\draw[xshift=\x cm] (-4,0) -- (-4,0.1);
\draw[xshift=\x cm] (-4,0) -- (-4,0.1);

其中xshift和yshift分别表示左右平移和上下平移 。
tikz现在才明白它是用来画图的,他可以换各种各样的图,各种各样的几何图形他都可以画出来。
很长一段时间我都在寻找一个能够画几何图形的工具 tikz是其他工具中最好的。python也是可以画几何图形的,但从美观来看,不如tikz。python主要是用来处理数据,而不是画图。

5 参考网站

https://www.overleaf.com/learn/latex/LaTeX_Graphics_using_TikZ:A_Tutorial_for_Beginners(Part_1)%E2%80%94Basic_Drawing