如何绘制带有放大部分的图?

如何绘制带有放大部分的图?

在此处输入图片描述

如何添加缩放区域并给出和标记顶部 x 轴?

这是我的代码:

\begin{tikzpicture}
 \begin{axis}[
   scaled ticks=false,
   xmin=0,
   ymin=0,
   xlabel=In,
   ylabel=out,
 ]
    \addplot[domain=15:140, blue, ultra thick,smooth] {10000/(9999*e^(-0.125*x)+10)+120};


\end{axis}
\end{tikzpicture}
\hspace{1cm}
\begin{tikzpicture}
 \begin{axis}[
   scaled ticks=false,
   xmin=20,
   ymin=80,
   xlabel=In,
   ylabel=out,

 ]
    \addplot[domain=5:40, blue, ultra thick,smooth] {10000/(9999*e^(-0.125*x)+10)+100};

\end{axis}
\end{tikzpicture}

答案1

这是一条建议。代码中有一些注释,如果有什么不清楚的地方可以询问。

代码输出

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\usepackage{filecontents}

% if this is uncommented, all the instances of "axis cs:" below can be removed
%\pgfplotsset{compat=1.11}

% calc library required for the ($(..)+(..)$) coordinate syntax
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}[
  % as the function is used more than once, make a shorthand
  declare function={
   f(\x)=10000/(9999*e^(-0.125*\x)+10)+100;
  }
]
 \begin{axis}[
   scaled ticks=false,
   xmin=0,
   ymin=0,
   xlabel=In,
   ylabel=out,
   % add a name to the axis, used to position the second one
   name=ax1
 ]

 \addplot[domain=15:140, blue, ultra thick,smooth] {f(x)};

  % define coordinates at bottom left and top left of rectangle
  \coordinate (c1) at (axis cs:20,80);
  \coordinate (c2) at (axis cs:20,240);
  % draw a rectangle
  \draw (c1) rectangle (axis cs:42,240);


\end{axis}

 \begin{axis}[
   name=ax2,
   scaled ticks=false,
   xmin=20,xmax=42,
   ymin=80,ymax=240,
   xlabel=In,
   ylabel=out,
   % place second axis relative to first one
   % anchor is south west
   at={($(ax1.south east)+(2cm,0)$)},
   % turn on grid
   xmajorgrids=true,
   grid style={help lines,dashed},
   % to avoid clipping of a...e nodes
   clip=false
 ]
    \addplot[domain=20:40, blue, ultra thick,smooth] {f(x)};


    \foreach \x/\txt in {20/a,25/b,30/c,35/d,40/e}
    {
     \edef\temp{\noexpand\draw [dashed] (axis cs:\x,{f(\x)}) coordinate (tmp) -- ({rel axis cs:0,0}|-tmp) node[left] {\txt};}
      \temp
    }

\end{axis}

% third axis for the top axis
\begin{axis}[
at={(ax2.south west)},
% put x-axis labels etc. on top
axis x line=top,
% remove arrow tip
axis line style={-},
axis y line=none,
xmin=20,xmax=42,
ymin=0,ymax=5,
xlabel=stuff,
xticklabels={,10,9,8,7,6}
]

\end{axis}

% draw dashed lines from rectangle in first axis to corners of second
\draw [dashed] (c1) -- (ax2.south west);
\draw [dashed] (c2) -- (ax2.north west);
\end{tikzpicture}
\end{document}

相关内容