Pgfplots:如何使图超出轴

Pgfplots:如何使图超出轴

我正在使用 pgfplots 绘制一个尖峰。我只想将 y 轴绘制到 (4)。但是我希望尖峰本身​​的绘图能够延伸到 y 轴之外(比如说直到 10)。

有没有办法做到这一点?这是我目前的代码:

\documentclass{article}
\usepackage{pgfplots}

\pgfkeys{/pgfplots/Axis Style/.style={
width=4.5cm, height=5.8cm,
axis x line=center, 
axis y line=middle, 
samples=300,
ymin=-1, ymax=6,
xmin=-1, xmax=4,
domain=-1:4,
 }}

\begin{document}
\begin{center}
\begin{tikzpicture}
\begin{axis}[font=\scriptsize,every axis legend/.append style={ legend pos=north east,font=\scriptsize},
  Axis Style,
  ytick={-1,1,2,3},yticklabels={$-1$,$1$,$2$,$3$},
  xtick={-1,1,2,3},xticklabels={$-1$,$1$,$2$,$3$},
  xlabel={$x$}, ylabel={$y=\frac{x(x-3.01)}{x-3}$},
  xticklabel shift=9pt,
  legend style={draw=none},
  tick style={color=black},
  x label style={anchor=west},
  y label style={anchor=south west} ]
  \addplot plot[mark=none,  thick, black] (\x,{(\x)/(\x-3)*(\x-3.01)});
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}

答案1

该选项clip=false可实现您想要的功能。

进一步改进和控制实际情节可以提供关键的restrict y to domain、、unbounded coords和。samplessamples at

代码

\documentclass[tikz,convert=false]{standalone}
\usepackage{pgfplots}

\pgfplotsset{Axis Style/.style={
  width=4.5cm, height=5.8cm,
  axis x line=center, 
  axis y line=middle, 
  samples=300,
  ymin=-1, ymax=6,
  xmin=-1, xmax=4,
  domain=-1:4,
}}

\begin{document}
\begin{tikzpicture}
\begin{axis}[font=\scriptsize,every axis legend/.append style={ legend pos=north east,font=\scriptsize},
  Axis Style,
  ytick={-1,1,2,3},yticklabels={$-1$,$1$,$2$,$3$},
  xtick={-1,1,2,3},xticklabels={$-1$,$1$,$2$,$3$},
  xlabel={$x$}, ylabel={$y=\frac{x(x-3.01)}{x-3}$},
  xticklabel shift=9pt,
  legend style={draw=none},
  tick style={color=black},
  x label style={anchor=west},
  y label style={anchor=south west},
  clip=false,
  restrict y to domain=-1:17,
  unbounded coords=jump
   ]
  \addplot plot[mark=none, samples=1000, thick, black] (\x,{(\x)/(\x-3)*(\x-3.01)});
\end{axis}
\end{tikzpicture}
\end{document}

输出

在此处输入图片描述

相关内容