移动每个轴上的刻度标记但保留默认刻度标记

移动每个轴上的刻度标记但保留默认刻度标记

我想移动 x 轴上的一个刻度标记和 y 轴上的一个刻度标记。标有 的唯一刻度标记16,000/3\sqrt{3}应移至 y 轴的右侧,标有 的刻度标记20/\sqrt{3}应移至 x 轴上方。必须有类似于 的规范才能yticklabel style={anchor=west},使用。

此外,图表会覆盖多个刻度线。我以为规范fill=white会阻止这种情况发生。我记得有一个命令可以在图表上打印轴。

\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}


\noindent \hspace*{\fill}
\begin{tikzpicture}
\begin{axis}[width=6in,clip=false,
    axis lines=middle,
    xmin=-25,xmax=25,
    domain=-25:25,
    xlabel=$x$,ylabel=$y$,
    ymin=-3100,ymax=3100,
    restrict y to domain=-3100:3100,
    enlargelimits={abs=0.5cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xtick={},ytick={},
    extra x ticks={11.547},
    extra x tick labels={$\frac{20}{\sqrt{3}}$},
    extra y ticks={3079.2},
    extra y tick labels={$\frac{16,000}{3\sqrt{3}}$},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot[samples=501,domain=0:20,blue] {400*x - x^3};
\addplot[samples=501,dashed,domain=20:25,blue] {400*x - x^3};
\addplot[samples=501,dashed,domain=-25:0,blue] {400*x - x^3} node[right,pos=0.25,font=\footnotesize]{$y = 400x - x^{3}$};
\end{axis}
\end{tikzpicture}
\hspace{\fill}
\vskip0.25in

\end{document}

答案1

extra x/y ticks label您可以通过以下方式设置控制 s 的位置extra x/y tick style

extra x tick style={x tick label style={above, yshift=0.6ex}},
extra y tick style={y tick label style={right, xshift=0.3em}},

在此处输入图片描述

\node或者,您也可以使用坐标系放置标签axis cs

\node [above] at (axis cs: 11.547,0) {\tiny$\frac{20}{\sqrt{3}}$};
\node [right] at (axis cs: 0,3079.2) {\tiny$\frac{16,000}{3\sqrt{3}}$};

笔记:

  • 至于您关于覆盖节点的问题,这就是fill=white正在做的事情。如果添加,您可以看到节点的大小draw=red。即ticklabel style={font=\tiny,fill=white, draw=red}。此额外填充是通过控制的inner sep,因此通过将其设置为零,ticklabel style={font=\tiny,fill=white, draw=red, inner sep=0}您将看到节点现在只有文本的大小,并且重叠减少了(当然,实际文本与其他文本重叠的情况除外)。

参考:


代码:extra x/y tick 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}


\noindent \hspace*{\fill}
\begin{tikzpicture}
\begin{axis}[width=6in,clip=false,
    axis lines=middle,
    xmin=-25,xmax=25,
    domain=-25:25,
    xlabel=$x$,ylabel=$y$,
    ymin=-3100,ymax=3100,
    restrict y to domain=-3100:3100,
    enlargelimits={abs=0.5cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    extra x tick style={x tick label style={above, yshift=0.6ex}},
    extra y tick style={y tick label style={right, xshift=0.3em}},
    xtick={},ytick={},
    extra x ticks={11.547},
    extra x tick labels={$\frac{20}{\sqrt{3}}$},
    extra y ticks={3079.2},
    extra y tick labels={$\frac{16,000}{3\sqrt{3}}$},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot[samples=501,domain=0:20,blue, ultra thick] {400*x - x^3};
\addplot[samples=501,dashed,domain=20:25,blue, ultra thick] {400*x - x^3};
\addplot[samples=501,dashed,domain=-25:0,blue, ultra thick] {400*x - x^3} node[right,pos=0.25,font=\footnotesize]{$y = 400x - x^{3}$};
\end{axis}
\end{tikzpicture}
\hspace{\fill}
\vskip0.25in

\end{document}

代码:\nodeplacement

\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}
\noindent
\begin{tikzpicture}
\begin{axis}[width=6in,clip=false,
    axis lines=middle,
    xmin=-25,xmax=25,
    domain=-25:25,
    xlabel=$x$,ylabel=$y$,
    ymin=-3100,ymax=3100,
    restrict y to domain=-3100:3100,
    enlargelimits={abs=0.5cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xtick={},ytick={},
    extra x ticks={11.547},
    extra x tick labels={},% <-- placed via a \node
    extra y ticks={3079.2},
    extra y tick labels={},% <-- placed via a \node
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot[samples=501,domain=0:20,blue, ultra thick] {400*x - x^3};
\addplot[samples=501,dashed,domain=20:25,blue, ultra thick] {400*x - x^3};
\addplot[samples=501,dashed,domain=-25:0,blue, ultra thick] {400*x - x^3} node[right,pos=0.25,font=\footnotesize]{$y = 400x - x^{3}$};

\node [above] at (axis cs: 11.547,0) {\tiny$\frac{20}{\sqrt{3}}$};
\node [right] at (axis cs: 0,3079.2) {\tiny$\frac{16,000}{3\sqrt{3}}$};
\end{axis}
\end{tikzpicture}%
\end{document}

相关内容