Labelnode 不垂直移动

Labelnode 不垂直移动

我试图将顶部带有 2 和 3 的两条线向下移动,以便该线与 y 轴的左上角相连。不知何故它没有移动。我知道缩放很奇怪,可能是整个混乱的原因,但我需要它才能在文档中进行正确的缩放。

\documentclass[letter,11pt,twoside]{book}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplotstable}

\begin{document}


\begin{center}
\begin{tikzpicture}[scale=0.90,
  labelnode/.style={font=\footnotesize, above},
  labelline/.style={stealth-stealth,shorten >=0.1pt, shorten <=0.5pt}
]
\begin{axis}[
    axis lines = left,
    xlabel = $\beta$,
    ylabel = {$E\left[\pi_B^D\right]$},
    width=16cm,
    height=8cm,
    xmin=2, xmax=8.2, ymin=340, ymax=480,
xtick={2,3,4,5,6,7,8},
xticklabels={2,3,4,5,6,7,8},
]
\addplot [
    domain=2 : 5.587,
    samples=100,
    color=red     ] {275 + 50 * 10^(2/3) * (1/x)^(2/3)} ;
\coordinate (l) at (rel axis cs:0,1);
\path (-10, 1000 |- l) coordinate (aux1)
(318, 1000 |- l)  coordinate (aux2)
(550, 1000 |- l) coordinate (aux3);
\end{axis}
\draw [labelline] (aux1) -- node[labelnode]{$2$} (aux2);
\draw [labelline] (aux2) -- node[labelnode]{$3$} (aux3);
\end{tikzpicture}
\end{center}

\end{document}

先感谢您

答案1

您正在使用旧的兼容模式,并添加scale=0.9到 的选项中tikzpicture。如果您切换到较新的版本,则不再需要axis cs:scale您可以调整绘图的宽度和高度来减小绘图的大小,而不是在令人困惑的scale环境中。tikzpicturepgfplots

\documentclass[letter,11pt,twoside]{book}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}


\begin{center}
\begin{tikzpicture}[
  labelnode/.style={font=\footnotesize, above},
  labelline/.style={stealth-stealth,shorten >=0.1pt, shorten <=0.5pt}
]
\begin{axis}[
    axis lines = left,
    xlabel = $\beta$,
    ylabel = {$E\left[\pi_B^D\right]$},
    width=16cm,
    height=8cm,
    xmin=2, xmax=8.2, ymin=340, ymax=480,
xtick={2,3,4,5,6,7,8},
xticklabels={2,3,4,5,6,7,8},
]
\addplot [
    domain=2 : 5.587,
    samples=100,
    color=red     ] {275 + 50 * 10^(2/3) * (1/x)^(2/3)} ;
\coordinate (l) at (rel axis cs:0,1);
\path (2,0 |- l) coordinate (aux1)
 (5,0 |- l)  coordinate (aux2)
 (8,0 |- l) coordinate (aux3);
\end{axis}
\draw [labelline] (aux1) -- node[labelnode]{$2$} (aux2);
\draw [labelline] (aux2) -- node[labelnode]{$3$} (aux3);
\end{tikzpicture}
\end{center}
\end{document}

在此处输入图片描述

相关内容