我有函数 y = 15x - (1/4)x^{3} 的图。我在20\sqrt{5}
y 轴上用 标记该函数的局部最大值。我在 y 轴上还有其他刻度标记。我希望默认刻度标记保留在 y 轴的左侧,并且只想将额外的刻度标记移动到 y 轴的右侧。为什么命令会将extra y tick style={y tick label style={right, xshift=0.25em}},
所有刻度标记移动到 y 轴的右侧?哪些代码可以给我关于刻度标记的我想要的内容?
\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=5in,axis on top,clip=false,
axis lines=middle,
xmin=-10,xmax=10,
domain=-10:10,
xlabel=$x$,ylabel=$y$,
ymin=-50,ymax=50,
restrict y to domain=-50:50,
enlargelimits={abs=0.5cm},
axis line style={latex-latex},
ticklabel style={font=\tiny,fill=white},
xtick={\empty},ytick={},
extra x ticks={-4.4721, 4.4721},
extra x tick labels={$-2\sqrt{5}$, $2\sqrt{5}$},
extra y ticks={44.721},
extra y tick labels={$20\sqrt{5}$},
extra y tick style={y tick label style={right, xshift=0.25em}},
yticklabel style={anchor=west},
xlabel style={at={(ticklabel* cs:1)},anchor=north west},
ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot[samples=501,domain=0:7.746,blue] {15 * x - 0.25 * x^3};
\addplot[samples=501,dashed,domain=7.746:10,blue] {15 * x - 0.25 * x^3};
\addplot[samples=501,dashed,domain=-10:0,blue] {15 * x - 0.25 * x^3} node[right,pos=0.1,font=\footnotesize]{$y = 15x - \dfrac{1}{4} \, x^{3}$};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
这yticklabel style={anchor=west}
是导致标签贴错的罪魁祸首。注释掉它会产生以下结果:
笔记:
- 我还改变了它,
fill
因为ticklabel style={font=\tiny,fill=none}
它使一些图表变白了。
代码:
\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=5in,axis on top,clip=false,
axis lines=middle,
xmin=-10,xmax=10,
domain=-10:10,
xlabel=$x$,ylabel=$y$,
ymin=-50,ymax=50,
restrict y to domain=-50:50,
enlargelimits={abs=0.5cm},
axis line style={latex-latex},
ticklabel style={font=\tiny,fill=none},% <-- changed from fill=none
xtick={\empty},ytick={},
extra x ticks={-4.4721, 4.4721},
extra x tick labels={$-2\sqrt{5}$, $2\sqrt{5}$},
extra y ticks={44.721},
extra y tick labels={$20\sqrt{5}$},
extra y tick style={y tick label style={right, xshift=0.25em}},
%yticklabel style={anchor=west},
xlabel style={at={(ticklabel* cs:1)},anchor=north west},
ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot[samples=501,domain=0:7.746,blue] {15 * x - 0.25 * x^3};
\addplot[samples=501,dashed,domain=7.746:10,blue] {15 * x - 0.25 * x^3};
\addplot[samples=501,dashed,domain=-10:0,blue] {15 * x - 0.25 * x^3} node[right,pos=0.1,font=\footnotesize]{$y = 15x - \dfrac{1}{4} \, x^{3}$};
\end{axis}
\end{tikzpicture}
\end{document}