图中节点的正确排列

图中节点的正确排列

看看下面这个例子。你可以观察到我的图中有六个节点。现在我的问题是,如何在不使用 \foreach 的情况下手动放置所有这些节点。因为图中有些节点排列不正确。在此处输入图片描述

这是我的 MWE:

\documentclass[12pt, a4paper]{article}
\usepackage[a4paper,top=1 in,bottom=1 in,left=0.7 in,right=0.7 in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}    
\begin{tikzpicture}
\draw[thick,latex-latex] (-8,0) -- (8,0)node[right]{$x$};
\draw[thick,latex-latex] (0,-8) -- (0,8)node[above]{$y$};
\node at (-0.3,-0.3) {O};
\foreach \x/\l in {-7/-7,-6/-6,-5/-5,-4/-4,-3/-3,-2/-2,-1/-1,1/1,2/2,3/3,4/4,5/5,6/6,7/7}{
    \node[fill,circle,inner sep=1.5pt,label=below:$\l$] at (\x,0) {};
    \node[fill,circle,inner sep=1.5pt,label=left:$\l$] at (0,\x) {};
}
\draw[thick,stealth-stealth, shorten >= -1cm, shorten <= -1cm,name path =b ](-7,5) --(0,6)-- (7,7);
\draw[thick,stealth-stealth, shorten >= -2cm, shorten <= -2cm](0,-2)-- (3, -1) -- (6,0) ;

\foreach \x/\y/\name in {0/6/,-7/5/,7/7/}{
    \node[fill,circle,inner sep=2.5pt,label={[inner sep=2pt]above right:\name($\x, \y$)}] at (\x,\y) {};
};
\foreach \x/\y/\name in {0/-2/,3/-1/,6/0/}{
    \node[fill,circle,inner sep=2.5pt,label={[inner sep=12pt]below right:\name($\x, \y$)}] at (\x,\y) {};
};
\end{tikzpicture}  

\end{document}

答案1

当你制作轴和图时,你可以使用pgfplots。在这里你也可以使用tikz包来绘制简单的图形,通过(axis cs: x,y)

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}    
\begin{tikzpicture}[scale=0.5]
\begin{axis}[
    axis lines=middle,
    domain = -8:8,
    xmin = -8,
    xmax = 8,
    ymin = -8,
    ymax = 8,
    x=1cm,
    y=1cm,
    thick,
]
\draw[fill] (axis cs: -7,5) node[above] {$(-7,5)$} circle(2pt)
    -- (axis cs: 0,6)  node[above right] {$(0,6)$} circle(2pt)
    -- (axis cs: 7,7) node[above] {$(7,7)$} circle(2pt);
\path (axis cs: -7,5) -- (axis cs: 7,7) coordinate[pos=-1/20] (A);      
\path (axis cs: 7,7) -- (axis cs: -7,5) coordinate[pos=-1/20] (B);   
\draw[->] (axis cs: -7,5) -- (A);
\draw[->] (axis cs: 7,7) -- (B);
%or you could do it like this
\draw[fill] (axis cs: 0,-2) node[below right] {$(0,-2)$} circle(2pt);
\draw[fill] (axis cs: 3,-1) node[below right] {$(3,-1)$} circle(2pt);
\draw[fill] (axis cs: 6,0)  node[above left] {$(6,0)$} circle(2pt);
\addplot[<->,domain=-0.15:1.15,variable=\t] 
({\t*(0)+(1-\t)*6},{\t*(-2)+(1-\t)*0});
\end{axis}
\end{tikzpicture} 
\end{document}

相关内容