帮助制作特定的 2D 片段

帮助制作特定的 2D 片段

几天前,我在这个论坛上问过在 tikz 中绘制一维线段的方法。你们帮了大忙。

我尝试修改我得到的代码,以便以二维方式绘制相同的线段,但我无法做到。我可以再次寻求您的帮助吗? 帮助

这是我用于一维图像的代码:

\begin{tikzpicture}
    \draw (-6,0) -- (6,0) ; 
    \foreach \x/\y in  {-6/{$x-2h$},-3/{$x-h$},0/{$x$},3/{$x+h$},6/{$x+2h$}}  
    \draw[shift={(\x,0)},color=black] (0pt,3pt) -- (0pt,-3pt)node[below] {\y};
    \foreach \x/\y in {-6/-3,-3/0,0/3,3/6}
    \draw[bend left,looseness=1.4, shorten >=4pt,shorten <=4pt, blue, thick](\x,0)to node[ label=90: 1/2]{}(\y,0);
\end{tikzpicture}

答案1

正如@Sigur所建议的,只需切换 x 和 y 值:

\documentclass[border=5pt]{standalone}

\usepackage{tikz}

\tikzset{%
    every node/.style={font=\strut},
}

\begin{document}
    \begin{tikzpicture}[]
        \draw (-6,0) -- (6,0) ; 
        \foreach \x/\y in  {-6/{$x-2h$},-3/{$x-h$},3/{$x+h$},6/{$x+2h$}}  
        \draw[shift={(\x,0)},color=black] (0pt,3pt) -- (0pt,-3pt)node[below] {\y};
        \foreach \x/\y in {-6/-3,-3/0,0/3,3/6}
        \draw[bend left,looseness=1.4, shorten >=4pt,shorten <=4pt, blue, thick](\x,0)to node[above, blue]{1/2}(\y,0);
        
        \node[below right] at (3pt,-3pt) {$x$};
        
        \draw (0,-6) -- (0,6) ; 
        \foreach \x/\y in  {-6/{$x-2h$},-3/{$x-h$},3/{$x+h$},6/{$x+2h$}}  
        \draw[shift={(0,\x)},color=black] (-3pt,0pt) -- (3pt,0pt)node[right] {\y};
        \foreach \x/\y in {-6/-3,-3/0,0/3,3/6}
        \draw[bend left,looseness=1.4, shorten >=4pt,shorten <=4pt, blue, thick](0,\x)to node[left, blue]{1/2}(0,\y);
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容