y 标签和 x 标签的问题

y 标签和 x 标签的问题

我对轴标签有疑问。当我缩小图表时,它改变了我的位置,它们看起来不像应该的那样。如果我将比例设置为 1,它看起来不错,但我改变了比例,弄乱了轴标签(ylabel 和 xlabel)。

\begin{tikzpicture}[scale=0.9]
    \begin{axis}[
axis lines=center,
grid={both}, 
clip=false,
grid style={solid,black!75},
y axis line style={very thick,-Stealth},
x axis line style={very thick,-Stealth},
ytick={0,2}, 
xmin=-0.5,xmax=4.5,
ymax=4,ymin=-1,
extra y ticks={-1,3,4},
extra y tick labels={},
extra y tick style={ticklabel style={fill=none}},
minor tick num=1,
ylabel={$i_{(t)}$}, xlabel={$t$},
ylabel style={above}, 
xlabel style={right}, 
ticklabel style={fill=black!20,circle,inner sep=2pt},
scale only axis,
width=8cm,
height=4cm
]
% changed from draw to addplot
\addplot [ultra thick,blue] coordinates{(0,2)(0.5,2)};
\addplot [ultra thick,blue] coordinates{(2.5,2)(3,2)};
\addplot[ultra thick,blue,domain=0.5:2.5,samples=100)]{-2*sin(deg(pi*x/2-pi/4))+2};
\addplot[ultra thick,blue,dashed,domain=3:4,samples=100)]{-2*sin(deg(pi*x/2-3*pi/2))+2};
\end{axis}
\end{tikzpicture}

在此处输入图片描述

提前致谢!

答案1

选择足够高的 pgfplots 版本。任何版本\pgfplotsset{compat=1.8}或更高版本都足够,但当然值得完全更新 TeX 安装并选择\pgfplotsset{compat=1.17}

\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{arrows.meta}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{tikzpicture}[scale=0.9]
    \begin{axis}[
      axis lines=center,
      grid={both}, 
      clip=false,
      grid style={solid,black!75},
      y axis line style={very thick,-Stealth},
      x axis line style={very thick,-Stealth},
      ytick={0,2}, 
      xmin=-0.5,xmax=4.5,
      ymax=4,ymin=-1,
      extra y ticks={-1,3,4},
      extra y tick labels={},
      extra y tick style={ticklabel style={fill=none}},
      minor tick num=1,
      ylabel={$i_{(t)}$}, xlabel={$t$},
      ylabel style={above}, 
      xlabel style={right}, 
      ticklabel style={fill=black!20,circle,inner sep=2pt},
      scale only axis,
      width=8cm,
      height=4cm
      ]
% changed from draw to addplot
\addplot [ultra thick,blue] coordinates{(0,2)(0.5,2)};
\addplot [ultra thick,blue] coordinates{(2.5,2)(3,2)};
\addplot[ultra thick,blue,domain=0.5:2.5,samples=100)]{-2*sin(deg(pi*x/2-pi/4))+2};
\addplot[ultra thick,blue,dashed,domain=3:4,samples=100)]{-2*sin(deg(pi*x/2-3*pi/2))+2};
\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

未来,我希望你们能为社区提供最低限度但完全的代码以 开头\documentclass,以 结尾\end{document}

相关内容