我们如何在 y 轴上绘制从 (0,2) 到 (0,4) 的区间,我们在 x 轴上绘制它。
\documentclass[tikz, border={0pt 0pt 0pt 6pt}]{standalone}
\usetikzlibrary{arrows,decorations.markings}
\usetikzlibrary{arrows.meta}% CVS
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=0.7, baseline={(current bounding box.north)}]
\draw[step=1cm,color=gray!20] (-3,-2) grid (6,6);
\draw[-] (-3,0) -- (4,0) node[right] {$x$};
\draw (0,0) node[below right] {$0$};
\draw[-] (0,-2) -- (0,6) node[above] {$y$};
\foreach \x in { -2, -1, 1, 2, 3, 4}
\draw (\x cm,1pt) -- (\x cm,-1pt) node[anchor=north] {$\x$};
\foreach \y in {-2, -1, 1, 3,6}
\draw (1pt,\y cm) -- (-1pt,\y cm) node[anchor=east] {$\y$};
\clip (-3,-2) rectangle (6,6);
\draw[scale=1,smooth,variable=\x,black,domain=-2:1] plot ({\x},{\x});
\draw[scale=1,smooth,variable=\x,black,domain=1:3] plot ({\x},{(3)*\x});
\draw[fill=white](1,1) circle(0.7mm);
\draw[fill=black](1,3) circle(0.7mm);
\draw[decoration={
markings, mark=at position .2 with {\arrow[line width=.7\pgflinewidth,scale=2]{[}},
mark=at position .8 with {\arrow[line width=.7\pgflinewidth,scale=2]{)}}},
postaction=decorate]
(+0pt,+0pt) -- node[pos=.2, below=+3pt] {} node[pos=.8, below=+3pt] {} ++(right:+70pt);
\end{tikzpicture}
\end{center}
\end{document}
答案1
像这样?
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}[scale=0.7,
dot/.style = {circle, draw, fill=#1, minimum size=2mm, inner sep=0pt,
node contents={}}
]
\draw[step=1cm,color=gray!20] (-3,-2) grid (6,6);
% axis and ticks
\draw[-] (-3,0) -- (4,0) node[right] {$x$};
\draw[-] (0,-2) -- (0,6) node[above] {$y$};
\foreach \x in { -2, -1,...,4}
\draw (\x,2pt) -- ++ (0,-4pt) node[fill=white,anchor=north] {$\x$};
\foreach \y in { -2, -1,1,3,5}
\draw (2pt,\y) -- ++ (-4pt,0) node[anchor=east] {$\y$};
% function
\draw[thick] (-2,-2) -- (1,1) node[dot=white]
(1,3) node[dot=black] -- (2,6);
% INTERVAL
\draw[{Parenthesis[width=4mm]}-{Bracket[width=4mm]}, thick] (0,2) -- (0,4);
\end{tikzpicture}
\end{document}