我正在绘制一个格子(向量空间),如下所示:
使用以下 tikz 代码
\begin{tikzpicture}
\draw[ultra thick,->] (0,0) -- (9,0) node[anchor=north west] {x axis};
\draw[ultra thick,->] (0,0) -- (0,9) node[anchor=south east] {y axis};
\foreach \x in {0,1,2,3,4,5,6,8,9}
\draw (\x cm,1pt) -- (\x cm,-1pt) node[anchor=north] {$\x$};
\foreach \y in {0,1,2,3,4,5,6,7,8,9}
\draw (1pt,\y cm) -- (-1pt,\y cm) node[anchor=east] {$\y$};
\draw[step=1cm,gray,very thin] (0,0) grid (8,8);
\draw[->, ultra thick, blue](0,0) -- (1,0);
\draw[->, ultra thick, red](0,0) -- (0,1);
\node[draw,circle,inner sep=3pt,fill] at (1,4) {};
\node[draw,circle,inner sep=1pt,fill] at (0,2) {};
\node[draw,circle,inner sep=1pt,fill] at (0,6) {};
\node[draw,circle,inner sep=1pt,fill] at (6,0) {};
\node[draw,circle,inner sep=1pt,fill] at (2,0) {};
\node[draw,circle,inner sep=1pt,fill] at (2,4) {};
\end{tikzpicture}
为什么只绘制了点 (1,4)?为什么没有绘制其他点 (0,2)、(0,6)...?
我认为代码的最后 6 行缺少正确的语法。
编辑:我解决了
答案1
如果您将网格线作为 \tikzpicture 环境中的第一条线,则所有点都是可见的。如果网格线的颜色为灰色,效果会更好!例如 20。
输出:
添加回答 Zarko 的评论:
\documentclass[10pt,a4paper]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[step=1cm,gray,very thin] (0,0) grid (8,8);
\draw[ultra thick,->] (0,0) -- (9,0) node[anchor=north west] {x axis};
\draw[ultra thick,->] (0,0) -- (0,9) node[anchor=south east] {y axis};
\foreach \x in {0,1,2,3,4,5,6,7,8,9}
\draw (\x cm,1pt) -- (\x cm,-1pt) node[anchor=north] {$\x$};
\foreach \y in {0,1,2,3,4,5,6,7,8,9}
\draw (1pt,\y cm) -- (-1pt,\y cm) node[anchor=east] {$\y$};
\draw[->, ultra thick, blue](0,0) -- (1,0);
\draw[->, ultra thick, red](0,0) -- (0,1);
\node[draw,circle,inner sep=3pt,fill] at (1,4) {};
\node[draw,circle,inner sep=1pt,fill] at (0,2) {};
\node[draw,circle,inner sep=1pt,fill] at (0,6) {};
\node[draw,circle,inner sep=1pt,fill] at (6,0) {};
\node[green,draw,circle,inner sep=1pt,fill] at (2,0) {};
\node[draw,circle,inner sep=1pt,fill] at (2,4) {};
\end{tikzpicture}
\end{document}
答案2
大部分主题,由于您的代码片段生成所需的图像,但点/圆圈的代码不一致,请参阅@learner 评论。
请始终提供 MWE(最小工作示例),这是一个完整的小文档,我们可以按原样编译它并重现您的问题。
我会按照以下方式绘制你的图像:
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}[
arr/.style = {color=#1, very thick, -Stealth},
arr/.default = black,
dot/.style = {circle, fill=#1, inner sep=2pt, node contents={}}
]
% axis
\draw[arr] (0,0) -- (9,0) node[below=1pt] {x axis};
\draw[arr] (0,0) -- (0,9) node[ left=1pt] {y axis};
% tick
\foreach \i in {0,1,...,8}
{
\draw (\i,1mm) -- ++ (0,-2mm) node[below] {\i};
\draw (1mm,\i) -- ++ (-2mm,0) node[left] {\i};
}
% unit vectors,
\draw[arr=blue] (0,0) -- (1,0);
\draw[arr= red] (0,0) -- (0,1);
% grid
\draw[step=1cm,gray,very thin] (0,0) grid (8,8);
% dots
\path (0,2) node[dot=cyan]
(1,4) node[dot=purple]
(2,4) node[dot=black]
(0,6) node[dot=teal];
\end{tikzpicture}
\end{document}
编辑:添加缺失的点。