帮助热线帮助

帮助热线帮助

我正在绘制通向两点的晶格路径。我想在笛卡尔平面上绘制辅助线,这样任何与轴距离为整数的线都是实线,任何与轴距离为 0.5 的奇数倍的线都是虚线。我绘制的辅助线甚至与轴不一致!

如何让OAB排版到帮助行上。[fill=white,circle,inner sep=0pt]我的代码忽略了该选项。因此,其中一条(放错位置的)帮助行被绘制在了它上面。

\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning}



\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}

\hspace*{\fill}
\begin{tikzpicture}
\begin{axis}[
    xmin=-11,xmax=11,ymin=-11,ymax=11,
    axis lines=middle,
    enlargelimits={abs=0.5},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
        ]

\coordinate (O) at (0,0);
\node[fill=white,circle,inner sep=0pt] (O-label) at ($(O)+(-135:10pt)$) {$O$};
\coordinate (A) at (-2.5,9.5);
\node[fill=white,circle] (A-label) at ($(A)+(-180:10pt)$) {$A$};
\coordinate (B) at (7,-3.5);
\node[fill=white,circle] (B-label) at ($(B)+(-45:10pt)$) {$B$};

\draw[fill] (O) circle (1.5pt);
\draw[fill] (A) circle (1.5pt);
\draw[fill] (B) circle (1.5pt);

%These commands are for drawing a path from O to A.
\coordinate (A1) at (-0.5,0);
\coordinate (A2) at (-.5,3);
\coordinate (A3) at (-2.5,3);

\draw[line width=1pt] (O) -- (A1) -- (A2) -- (A3) -- (A);

%These commands are for drawing a path from O to B.
\coordinate (B1) at (2,0);
\coordinate (B2) at (2,-2.5);
\coordinate (B3) at (5,-2.5);
\coordinate (B4) at (5,-3.5);
\coordinate (B) at (7,-3.5);

\draw[line width=1pt] (O) -- (B1) -- (B2) -- (B3) -- (B4) -- (B);

\draw[help lines,line width=0.1pt,blue] (-10.5, -10.5) grid (10.5,10.5);


\end{axis}
\end{tikzpicture}
\hspace{\fill}
\vskip0.25in

\end{document}

答案1

这也是对评论为了另一个回答另一个问题

要使帮助行叠印,必须先将它们打印在以下对象下方。该\draw命令应放在其他元素之前。

下一个问题是线条位置错误。以下命令至少在 (-10, -10) 至 (10, 10) 区域添加网格线:

\draw[
  help lines,
  line width=0.1pt,
  blue,
  shift={($(1, 1) - (0, 0)$)},
] (-11, -11) grid[step={($(5, 5) - (0, 0)$)}] (9, 9);

完整示例:

\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}   
\begin{tikzpicture}
\begin{axis}[
    xmin=-11,xmax=11,ymin=-11,ymax=11,
    axis lines=middle,
    enlargelimits={abs=0.5},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
        ]

\draw[
  help lines,
  line width=0.1pt,
  blue,
  shift={($(1, 1) - (0, 0)$)},
] (-11, -11) grid[step={($(5, 5) - (0, 0)$)}] (9, 9);

\coordinate (O) at (0,0);
\node[fill=white,circle,inner sep=0pt] (O-label) at ($(O)+(-135:10pt)$) {$O$};
\coordinate (A) at (-2.5,9.5);
\node[fill=white,circle] (A-label) at ($(A)+(-180:10pt)$) {$A$};
\coordinate (B) at (7,-3.5);
\node[fill=white,circle] (B-label) at ($(B)+(-45:10pt)$) {$B$};

\draw[fill] (O) circle (1.5pt);
\draw[fill] (A) circle (1.5pt);
\draw[fill] (B) circle (1.5pt);

%These commands are for drawing a path from O to A.
\coordinate (A1) at (-0.5,0);
\coordinate (A2) at (-.5,3); 
\coordinate (A3) at (-2.5,3);

\draw[line width=1pt] (O) -- (A1) -- (A2) -- (A3) -- (A);

%These commands are for drawing a path from O to B.
\coordinate (B1) at (2,0);   
\coordinate (B2) at (2,-2.5);
\coordinate (B3) at (5,-2.5);
\coordinate (B4) at (5,-3.5);
\coordinate (B) at (7,-3.5);

\draw[line width=1pt] (O) -- (B1) -- (B2) -- (B3) -- (B4) -- (B);

\end{axis}
\end{tikzpicture}
\end{document}   

结果

两个方向从 -11 到 11 的整个绘图区域均可由以下项覆盖:

\begin{scope}
  \clip (-11, -11) rectangle (11, 11);
  \draw[
    help lines,
    line width=0.1pt,
    blue,
    shift={($(1, 1) - (0, 0)$)},
  ] (-16, -16) grid[step={($(5, 5) - (0, 0)$)}] (10, 10);
\end{scope}

但是,轴刻度标签被帮助线覆盖。因此,我宁愿使用grid环境选项axis

\begin{axis}[
  ...,
  grid,
  grid options={line width=.1pt, draw=gray!30},
]
  ...
\end{axis}

结果网格选项

相关内容