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}

輸出

在此輸入影像描述

相關內容