我想绘制如下图所示的图形?
我尝试过并使用 Latex 代码得到了显示下图的图表?
\documentclass{standalone}
\standaloneconfig{border=2mm 2mm 2mm 2mm}
%maths
\usepackage{mathtools}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsfonts}
%tikzpicture
\usepackage{tikz}
\usepackage{scalerel}
\usepackage{pict2e}
\usepackage{tkz-euclide}
\usetikzlibrary{calc}
\usetikzlibrary{patterns,arrows.meta}
\usetikzlibrary{shadows}
\usetikzlibrary{external}
%pgfplots
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{statistics}
\usepgfplotslibrary{fillbetween}
%colours
\usepackage{xcolor}
\usepackage{nicefrac}
\begin{document}
\begin{tikzpicture}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\draw[help lines, color=gray!30, dashed] (-4.9,-4.9) grid (4.9,4.9);
\draw[->,ultra thick] (-2,0)--(5,0) node[right]{$x$};
\draw[->,ultra thick] (0,-2)--(0,5) node[above]{$y$};
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\draw(0,0)grid(5,5)
\draw[lightgray] (0,0) grid (5,5);
%\draw (1,1) -- (3,3);
%\draw[thick] (1,1) -- (3,3);
%\draw[ultra thick] (1.5,1.5) - - (3.5,1.5);
%\draw[ultra thick][Stealth-Stealth] (1.5,1.5) - - (3.5,1.5);
%\draw[ultra thick][Circle-Stealth] (1.5,1.5) - - (3.5,1.5);
\draw[{Circle[scale=2,open]}-{Stealth[scale=2]}] (1.5,1.5) -- (3.5,1.5) node[midway,above ] {$\mathbf{a}$};
\draw (0.5,0.5) circle [radius=0.1];
\fill[lightgray] (0.5,0.5) circle [radius=0.1];
\draw (0.5,1.5) circle [radius=0.1];
\fill[red] (0.5,1.5) circle [radius=0.1];
\draw (0.5,2.5) circle [radius=0.1];
\fill[lightgray] (0.5,2.5) circle [radius=0.1];
\draw (0.5,3.5) circle [radius=0.1];
\fill[lightgray] (0.5,3.5) circle [radius=0.1];
\draw (0.5,4.5) circle [radius=0.1];
\fill[lightgray] (0.5,4.5) circle [radius=0.1];
%%%%%%%%%%%%%%%%%%%%%%%%%%%
\draw (1.5,0.5) circle [radius=0.1];
\fill[lightgray] (1.5,0.5) circle [radius=0.1];
\draw (1.5,1.5) circle [radius=0.1];
\fill[red] (1.5,1.5) circle [radius=0.1];
\draw (1.5,2.5) circle [radius=0.1];
\fill[lightgray] (1.5,2.5) circle [radius=0.1];
\draw (1.5,3.5) circle [radius=0.1];
\fill[lightgray] (1.5,3.5) circle [radius=0.1];
\draw (1.5,4.5) circle [radius=0.1];
\fill[lightgray] (1.5,4.5) circle [radius=0.1];
%%%%%%%%%%%%%%%%%%%%%%%%%%%
\draw (2.5,0.5) circle [radius=0.1];
\fill[lightgray] (2.5,0.5) circle [radius=0.1];
\draw (2.5,1.5) circle [radius=0.1];
\fill[red] (2.5,1.5) circle [radius=0.1];
\draw (2.5,2.5) circle [radius=0.1];
\fill[lightgray] (2.5,2.5) circle [radius=0.1];
\draw (2.5,3.5) circle [radius=0.1];
\fill[lightgray] (2.5,3.5) circle [radius=0.1];
\draw (2.5,4.5) circle [radius=0.1];
\fill[lightgray] (2.5,4.5) circle [radius=0.1];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\draw (3.5,0.5) circle [radius=0.1];
\fill[lightgray] (3.5,0.5) circle [radius=0.1];
\draw (3.5,1.5) circle [radius=0.1];
\fill[red] (3.5,1.5) circle [radius=0.1];
\draw (3.5,2.5) circle [radius=0.1];
\fill[lightgray] (3.5,2.5) circle [radius=0.1];
\draw (3.5,3.5) circle [radius=0.1];
\fill[lightgray] (3.5,3.5) circle [radius=0.1];
\draw (3.5,4.5) circle [radius=0.1];
\fill[lightgray] (3.5,4.5) circle [radius=0.1];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\draw (4.5,0.5) circle [radius=0.1];
\fill[lightgray] (4.5,0.5) circle [radius=0.1];
\draw (4.5,1.5) circle [radius=0.1];
\fill[red] (4.5,1.5) circle [radius=0.1];
\draw (4.5,2.5) circle [radius=0.1];
\fill[lightgray] (4.5,2.5) circle [radius=0.1];
\draw (4.5,3.5) circle [radius=0.1];
\fill[lightgray] (4.5,3.5) circle [radius=0.1];
\draw (4.5,4.5) circle [radius=0.1];
\fill[lightgray] (4.5,4.5) circle [radius=0.1];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\draw (3.5,3.5) -- (4.5,3.5) -- (4.5,4.5) -- (3.5,4.5) -- (3.5,3.5) ;
\fill[red] (3.5,3.5) -- (4.5,3.5) -- (4.5,4.5) -- (3.5,4.5) -- (3.5,3.5) ;
\end{tikzpicture}
\end{document}
答案1
这是帮助您开始使用 TikZ 的第二张图片。
主要思想:
- 使用 TikZ
matrix
库matrix of math nodes
创建网格。设置节点的高度和宽度。 - 设置
row sep
和column sep
使得-\pgflinewidth
节点的边界重叠。 - 在下面的代码中,我调用了矩阵
(space)
。然后可以通过行号和列号引用单元格,例如,(space-1-2)
节点位于第 1 行、第 2 列。 - 我制作了宏
\oo
并\OO
用于未填充和填充的圆圈。 - 矩阵绘制完成后,使用普通的 TikZ 命令绘制箭头和标签。
- 绘制了 Delaunay 区域的矩形,
on background layer
因此网格和圆圈可见。 - 用于
\tikzset
定义右侧标签的专用虚线样式和线形节点。
以下是代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix, backgrounds}
\tikzset{mydash/.style={line width=.25pt, dash pattern=on 2.5pt off 2.5pt, shorten <=2mm, shorten >=-1.1mm},
linenode/.style={draw, inner sep=0pt, minimum height=6mm, minimum width=0mm, label={[align=left]right:{#1}}}}
\newcommand{\oo}{\scalebox{2}{$\circ$}}
\newcommand{\OO}{\scalebox{2}{$\bullet$}}
\begin{document}
\begin{tikzpicture}[font=\scriptsize]
\matrix (space) [matrix of math nodes, row sep=-\pgflinewidth, column sep=-\pgflinewidth,
nodes={draw, semithick, minimum height=15mm, minimum width=10mm, text=blue}]
{\oo & \oo & \oo \\
\oo & \oo & |[fill=gray!30]|\oo \\
\OO & \oo & \oo \\};
\draw[mydash] (space-1-1.center) --++ (0,1)node(a0){};
\draw[mydash] (space-1-2.center) --++ (0,1)node(b0){};
\draw[mydash] (space-1-1.center) --++ (-.7,0)node(a1){};
\draw[mydash] (space-2-1.center) --++ (-.7,0)node(b1){};
\scoped[on background layer]\draw[fill=gray!30] (space-1-1.center) rectangle (space-2-2.center);
\draw[<->] (a0.center) --node[above]{Spacing[0]} (b0.center);
\draw[<->] (b1.center) --node[sloped, above]{Spacing[1]} (a1.center);
\draw[<-, shorten <=2mm] (space-3-1.center) to[bend right] ++(.5,-1.5) node[below right]{Image Origin};
\draw[<-, shorten <=2mm, shorten >=2mm] (space-3-3.center) to[bend left] ++(1.5,0) node[right=-1mm]{Pixel Coordinates};
\draw[<-] ([yshift=4mm]space-2-3.center) to[bend left]++ (1.5,0)node[linenode=Pixel Coverage\\Voronoi Region]{};
\draw[<-] ([shift={(-2mm,-6mm)}]space-1-2.center) to[bend left]++ (2.7,1)node[linenode=Linear Interpolation Region\\Delaunay Region]{};
\end{tikzpicture}
\end{document}