我尝试画一些类似的东西:
为此,我使用 TikZ 编写了一些代码,但不幸的是,我没有得到我想要的。
\documentclass{report}
\usepackage{tikz}
\usetikzlibrary{automata,topaths}
\begin{document}
\begin{tikzpicture}[x=1cm,y=0.4cm]
\draw[<->] (-4,0)--(4,0); % l'axe des abscisses
\draw[<->] (0,-5)--(0,5); % l'axe des ordonnées
\draw[-] (-3,-2)--(3,4); % l'axe des abscisses
\draw (-2,1.5) node[anchor=south] {.};
\draw (-1,1) node[anchor=south] {.};
\draw (-2,3) node[anchor=south] {.};
\draw (-1,2.5) node[anchor=south] {.};
\draw (1,3) node[anchor=south] {.};
\end{tikzpicture}
\end{document}
结果是:
答案1
我建议你开始使用它pgfplots
来绘制图表。但是,如果你真的想使用 TikZ\node
来放置坐标,你可以使用循环\foreach
来简化事情:
\foreach \Point in {(-2,1.5), (-1,1), (-2,3), (-1,2.5), (1,3)}{
\node at \Point {\textbullet};
}
笔记:
- 红色和蓝色节点表示点正确地放置在坐标上。
代码:
\documentclass{report}
\usepackage{tikz}
%\usetikzlibrary{automata,topaths}% note neded for this.
\begin{document}
\begin{tikzpicture}[x=1cm,y=0.4cm]
\draw[latex-latex, thin, draw=gray] (-4,0)--(4,0) node [right] {$x$}; % l'axe des abscisses
\draw[latex-latex, thin, draw=gray] (0,-5)--(0,5) node [above] {$y$}; % l'axe des ordonnées
\draw[thick] (-3,-2)--(3,4); % l'axe des abscisses
\foreach \Point in {(-2,1.5), (-1,1), (-2,3), (-1,2.5), (1,3)}{
\node at \Point {\textbullet};
}
\foreach \Point in {(2,-1.5), (1,-1), (2,-3), (1,-2.5), (1,-3)}{
\node at \Point {$\circ$};
}
% to ensure that the points are being properly centered:
\draw [dotted, gray] (-4,-6) grid (5,5);
\node [red] at (3,2.5) {\textbullet};
\node [blue] at (3,-2.5) {$\circ$};
\end{tikzpicture}
\end{document}
答案2
只是为了展示如何做到这一点pgfplots
:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
xmin=-10, xmax=10,
ymin=-10, ymax=10,
xtick=\empty, ytick=\empty
]
\addplot [only marks] table {
-10 -4
-8 2
-5 5
-4 7
-3 3
0 6
};
\addplot [only marks, mark=o] table {
-4 -5
-2 -1
-1 -4
2 -3
4 3
6 -1
};
\addplot [domain=-10:10, samples=2, dashed] {1*x+3};
\end{axis}
\end{tikzpicture}
\end{document}
答案3
使用我的第一条评论的简单解决方案:
\documentclass[tikz]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[x=1cm,y=0.4cm]
\draw[-stealth] (-3,0)--(4,0) node[right]{x}; % x axis
\draw[-stealth] (0,-3)--(0,5) node[above]{y}; % y axis
\draw[dashed] (-3,-2)--(3,4) node[above]{H}; % a line...
\draw (-2,1.5) circle[radius=2pt];
\fill (-1,1) circle[radius=2pt];
\draw (-2,3) circle[radius=2pt];
\fill (-1,2.5) circle[radius=2pt];
\draw (1,3) circle[radius=2pt];
\end{tikzpicture}
\end{document}
答案4
如果你想画画带有标签的几个点最TikZ
简单的方法是
\foreach \Point/\PointLabel in {(1,1)/A, (3,1)/B, (1,4)/P_1, (3,4)/P_1}
\draw[fill=black] \Point circle (0.05) node[above right] {$\PointLabel$};
例子
代码
\documentclass[tikz]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
% help lines
\draw[step=1,help lines,black!20] (-0.95,-0.95) grid (4.95,4.95);
% axis
\draw[thick,->] (-1,0) -- (5,0);
\draw[thick,->] (0,-1) -- (0,5);
% points
\foreach \Point/\PointLabel in {(1,1)/A, (3,1)/B, (1,4)/P_1, (3,4)/P_1}
\draw[fill=black] \Point circle (0.05) node[above right] {$\PointLabel$};
\end{tikzpicture}
\end{document}