如何像下面这样用 TikZ 绘制数轴和阴影线?
答案1
仅用于 PSTricks 打字练习。未经简化,它包含487 个字符。
\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-eucl}
\begin{document}
\begin{pspicture}(-4,-.5)(7.5,1)
\psset{arrows=->}
\pstGeonode[PointName={-3,-2,4,6},PosAngle=-90](-3,0){A}(-2,0){B}(4,0){C}(6,0){D}
\uput{1.2}[0](D){$x$}
\ncline[nodesep=-1]{A}{D}
\psline(A)(A|0,1)([nodesep=-1,offset=1]A)
\psframe[fillstyle=hlines](C)(D|0,.5)
\psline{o-o}(B)(B|0,.5)(D|0,.5)(D)
\psline(C)(C|0,1)([nodesep=3,offset=1]C)
\end{pspicture}
\end{document}
为了获得更大的点和箭头,将 替换\psset{arrows=->}
为\psset{arrows=->,dotscale=2,arrowscale=2}
。因此输出变为如下。
答案2
最简单的tikz
解决方案:
\documentclass[varwidth,border=3pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}
\fill[even odd rule,pattern=north east lines,pattern color=black!30] (4, 0) rectangle (6, 1);
\draw[->] (-4, 0) -- (8, 0);
\draw (-2, 0) |- (4, 1) -| (6, 0);
\draw[->] (4, 0) |- (7, 2);
\draw[->] (-3, 0) |- (-4, 2);
\draw[fill=black] (-3, 0) circle (1mm) node[below] {$-3$};
\draw[fill=white] (-2, 0) circle (1mm) node[below] {$-2$};
\draw[fill=black] (4, 0) circle (1mm) node[below] {$4$};
\draw[fill=white] (6, 0) circle (1mm) node[below] {$6$};
\end{tikzpicture}
\end{document}