在 TikZ 中绘制图表

在 TikZ 中绘制图表

在此处输入图片描述

有谁愿意帮我用 LaTeX 画出这个图表吗?:-) 昨天我得到了帮助,画出了图表、点等等,但我不知道如何画出小框和点之间的线。

我昨天得到的代码,并尝试编辑......

\documentclass[margin=5mm]{standalone}
\usepackage{tikz}   
\usetikzlibrary{decorations.pathreplacing}    
\begin{document}
\begin{tikzpicture}[>=stealth,font=\scriptsize,scale=1.8]

 % draw axis

 \draw[->](0,0)--(4,0)node[below]{1};
 \draw[->](0,0)--(0,4)node[left]{1};;

 % draw ticks 

 \foreach \i in {1,2,3}
 {\draw (\i,0.1)--(\i,-0.1)node[below]{$\frac{\i}{4}$};
 \draw (0.1,\i)--(-0.1,\i)node[left]{$\frac{\i}{4}$};
 }

 % draw bullets 

 \foreach \i in {0,...,3}
 {\foreach \j in {0,...,3}
 \node[fill=black,circle,inner sep=1pt] (\i-\j) at (\i,\j) {};
 }

 % label for bullets x and y

 \node[below right] at (2-1){$y_{j}$};
 \node[below] at (1-2){$x_{j}$}; 
 \draw(1-2)--(2,2);
 \draw(1-2)--(1,3);
 \draw[dashed](2-2)--(2,3);
 \draw[dashed](1-3)--(2,3);
 \draw(2-1)--(3,1);
 \draw(2-1)--(2,2);
 \draw[dashed](3-1)--(3,2);
 \draw[dashed](2-2)--(3,2);
 %\draw[decorate,decoration={brace,raise=3pt}](1-2)--(3-2)node[midway,above=4pt] {$|x-y|_\infty$};

 % dashed arrows

 \draw[dashed,<->](0.2,0)--(0.2,1);
 \draw[dashed,<->](0,0.2)--(1,0.2)node[midway,above,font=\tiny]{$2^{-m}=\frac{1}{2}$};

\end{tikzpicture} 
\end{document}

答案1

要绘制交叉影线框,您可以在环境内使用\clip或限制显示沿着两个框边缘的路径内的对角线。\path[clip]scope

\clip(1,3)--(2,3)--(2,2)--(3,2)--(3,1)--(2,1)--(2,2)--(1,2)--cycle;

代码

\documentclass[margin=5mm]{standalone}
\usepackage{tikz}   
\usetikzlibrary{decorations.pathreplacing}    
\begin{document}
\begin{tikzpicture}[>=stealth,font=\scriptsize,scale=1.3]

 % draw axis

 \draw[->](0,0)--(6,0);
 \draw[->](0,0)--(0,6);

 % draw ticks 

 \draw (5,2pt)--(5,-2pt)node[below]{$1$};
 \draw (2pt,5)--(-2pt,5)node[left]{$1$};


 % draw bullets 

 \foreach \i in {0,...,4}
 {\foreach \j in {0,...,4}
 \node[fill=black,circle,inner sep=1pt]  at (\i,\j) {};
 }

 % label for bullets x and y

 \node[below] at (2,1){$y_{j}$};
 \node[below] at (1,2){$x_{j}$}; 
 \draw(1,2)--(2,2);
 \draw(1,2)--(1,3);
 \draw[dashed](2,2)--(2,3);
 \draw[dashed](1,3)--(2,3);
 \draw(2,1)--(3,1);
 \draw(2,1)--(2,2);
 \draw[dashed](3,1)--(3,2);
 \draw[dashed](2,2)--(3,2);

 % cross hatch boxes

 \begin{scope}
 \clip(1,3)--(2,3)--(2,2)--(3,2)--(3,1)--(2,1)--(2,2)--(1,2)--cycle;
 \foreach \sh in {-4,-3.9,...,4}
 {\draw[help lines] (1,1+\sh)--(3,3+\sh);}
 \end{scope}
 \draw[dashed](1.5,3)--(1.5,2)node[below,xshift=6pt]{$x_{j+1}$};
 \draw[dashed](1,2.5)--(2,2.5);
 \draw[dashed](2.5,2)--(2.5,1)node[below,xshift=6pt]{$y_{j+1}$};
 \draw[dashed](2,1.5)--(3,1.5);

 \node [fill=black,circle,inner sep=1pt,label=below:$x$ ]at(1.8,2.3){};
 \node [fill=black,circle,inner sep=1pt,label=below:$y$ ]at(2.2,1.8){};

 % dashed arrows

 \draw[dashed,<->](0.3,0)--(0.3,1);
 \draw[dashed,<->](0,0.3)--(1,0.3)node[pos=0.6,above,font=\tiny]{$2^{-j}$};

\end{tikzpicture} 
\end{document}

输出

在此处输入图片描述

答案2

PSTricks 解决方案:

\documentclass{article}

\usepackage{multido}
\usepackage{pstricks}

\begin{document}

\begin{pspicture}(-0.335,-0.415)(5.5,5.5) % frame parameters found manually
  \psline{->}(0,0)(5.5,0)
  \psline{->}(0,0)(0,5.5)
  \multido{\iA = 0+1}{5}{\multido{\iB = 0+1}{5}{\psdot(\iA,\iB)}}
  \psline(5,-0.1)(5,0.1)
  \uput[270](5,0){$1$}
  \psline(-0.1,5)(0.1,5)
  \uput[180](0,5){$1$}
 {\psset{linestyle = none, fillstyle = hlines}
  \psframe(1,2)(2,3)
  \psframe(2,1)(3,2)}
  \psline(1,3)(1,2)(2,2)(2,1)(3,1)
 {\psset{linestyle = dashed}
  \psline(1,3)(2,3)(2,2)(3,2)(3,1)
  \psline(1,2.5)(2,2.5)
  \psline(1.5,3)(1.5,2)
  \psline(2,1.5)(3,1.5)
  \psline(2.5,2)(2.5,1)
  \psline{<->}(0.4,0)(0.4,1)
  \psline{<->}(0,0.4)(1,0.4)}
 {\tiny
  \uput[45](0.4,0.4){$2^{-j}$}
  \uput[270](1,2){$x_{j}$}
  \uput[295](1.5,2){$x_{j + 1}$}
  \uput[270](2,1){$y_{j}$}
  \uput[295](2.5,1){$y_{j + 1}$}}
\end{pspicture}

\end{document}

输出

相关内容