以下代码指示 TikZ 绘制函数及其导数。我想要进行两项修改。由于函数在 0 处不可微,因此我希望在点 (0, -1) 和 (0, -2) 处有开口圆,并且由于导数的图形是黄色的,因此我希望圆也是黄色的。y 轴上的“-1”被导数的图形遮挡。我有fill=white
该命令的可选规范ticklabel style
,但它似乎被忽略了。
\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=6in,axis equal image,clip=false,
axis lines=middle,
xmin=-5.25,xmax=5,
domain=-5.25:5, samples=201,
xlabel=$x$,ylabel=$y$,
ymin=-6,ymax=6,
restrict y to domain=-6:6,
enlargelimits={abs=1cm},
axis line style={latex-latex},
ticklabel style={font=\tiny,fill=white},
xtick={-7,-6,-5,-4,-3,-2,-1,1,2,3,4,5,6,7},ytick={-7,-6,-5,-4,-3,-2,-1,1,2,3,4,5,6,7},
xlabel style={at={(ticklabel* cs:1)},anchor=north west},
ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot[samples=501,domain=-5:0,blue] {-x)};
\addplot[samples=501,domain=-5:0,yellow] {-1)};
\draw [fill=white, yellow] (0,-1) circle [radius=1.5pt];
\addplot[samples=501,domain=0:5,blue] {-2*x)} node[right,pos=0.9]{$\scriptstyle{y} = f(x)$};
\addplot[samples=501,domain=0:5,yellow] {-2)} node[right,pos=0.9]{$\scriptstyle{y} = f^{\prime}(x)$};
\draw [fill=white, yellow] (0,-2) circle [radius=1.5pt];
\end{axis}
\end{tikzpicture}
\end{document}
答案1
黄色真的是一个非常糟糕的线条颜色选择。您可以通过以下方式获取空心圆
fill=none, draw=black
使用draw=yellow
确实画出了开口圆,但是很难看见。
对于-1
y 刻度标签,我建议您将其省略。但是,如果您希望刻度标签出现在顶部,则需要使用layers
。否则刻度标签位于背景层上,该fill=
选项将不起作用。因此,添加选项
set layers=axis on top,
ticklabel style={font=\tiny, fill=white, circle, inner sep=0.5pt},
产量:
笔记:
对于圆圈,
fill=none
使用 选项而不是fill=white
。使用fill=none
可使下面的线可见。如果您不想要,则可以使用fill=white
。我添加了
inner sep=0.5pt
,以便将刻度标签周围的间距保持在较小范围内。默认设置inner sep
是.3333em
,这会导致刻度标签周围的空间相当大。
代码:
\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=6in,axis equal image,clip=false,
axis lines=middle,
xmin=-5.25,xmax=5,
domain=-5.25:5, samples=201,
xlabel=$x$,ylabel=$y$,
ymin=-6,ymax=6,
restrict y to domain=-6:6,
enlargelimits={abs=1cm},
axis line style={latex-latex},
ticklabel style={font=\tiny,fill=white},
xtick={-7,-6,-5,-4,-3,-2,-1,1,2,3,4,5,6,7},
ytick={-7,-6,-5,-4,-3,-2,1,2,3,4,5,6,7},
xlabel style={at={(ticklabel* cs:1)},anchor=north west},
ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot[samples=501,domain=-5:0,blue, thick] {-x)};
\addplot[samples=501,domain=-5:0,yellow, thick] {-1)};
\draw [fill=none, draw=black] (0,-1) circle [radius=1.5pt];
\addplot[samples=501,domain=0:5,blue, thick] {-2*x)} node[right,pos=0.9]{$\scriptstyle{y} = f(x)$};
\addplot[samples=501,domain=0:5,yellow, thick] {-2)} node[right]{$\scriptstyle{y} = f^{\prime}(x)$};
\draw [fill=none, draw=black] (0,-2) circle [radius=1.5pt];
\end{axis}
\end{tikzpicture}
\end{document}