tikz 中的轴缩短

tikz 中的轴缩短

我想知道是否可以绘制一个 x 轴(或 y 轴)图,其中包含以下形状之一,表明 x 轴不是从零开始?

我们也可以使用下表中的点来制作曲线吗?

在此处输入图片描述

在此处输入图片描述

    \documentclass[tikz]{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable} % For \pgfplotstableread

\pgfplotstableread{
100     35
55  30
}\datatablea

\pgfplotstableread{
55  20
100 21
}\datatableb

\pgfplotstableread{
55  50
100 56
}\datatablec
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=16,axis y discontinuity=crunch]
\addplot table  {\datatablea};
\addplot table  {\datatableb};
\addplot table  {\datatablec};
\end{axis}
\end{tikzpicture}
\end{document}

期望的数字: 在此处输入图片描述

答案1

代码输出

\documentclass[border=5mm]{standalone}
\usepackage{amsmath}
\usepackage{pgfplotstable} % For \pgfplotstablereadm also loads pgfplots
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.15}
\pgfplotstableread{
55  20
100 21
}\datatablea

\pgfplotstableread{
55  30
100     35
}\datatableb

\pgfplotstableread{
55  50
100 56
}\datatablec
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
  group style={
    % set number of axes, columns by rows
    group size=3 by 1,
    % we don't want any gap between axes
    horizontal sep=0pt
  },
  % the following settings apply to all three axes
  ymin=0,ymax=110,
  axis lines=middle,
  enlarge x limits=0.2,
  width=5cm,
  height=5cm,
  scale only axis,
  axis x discontinuity=crunch,
  xtick=data,
  ytick=data,
  longlines/.style={
    shorten >=-5mm,
    shorten <=-5mm
  },
  clip=false
]

% \nextgroupplot starts a new axis
\nextgroupplot[
  x axis line style={-}, % remove arrow tip
  width=2cm, % make this narrower
  xmin=19,
  ylabel=$P$
]

\addplot +[longlines] table[x index=1,y index=0]  {\datatablea}
node [above left, black] {$S_B$}
;
\coordinate (a100) at (\pgfkeysvalueof{/pgfplots/xmin},100);
\coordinate (a55) at (\pgfkeysvalueof{/pgfplots/xmin},55);

% plot vertical dashed lines
\addplot [ycomb,dashed,mark=none] table[x index=1,y index=0]  {\datatablea};


\nextgroupplot[
 hide y axis,  % don't want y-axis here
 x axis line style={-}
]

\addplot +[longlines] table[x index=1,y index=0]  {\datatableb}
node [above left, black] {$S_A$}
;

\addplot [ycomb,dashed,mark=none] table[x index=1,y index=0]  {\datatableb};

\nextgroupplot[
  hide y axis,
  xlabel={$Q_S$}
]

\addplot +[longlines] table[x index=1,y index=0]  {\datatablec}
coordinate [pos=0] (3a)
coordinate [pos=1] (3b)
node [above left, black] {$S_{\text{something}}$}
;

\addplot [ycomb,dashed,mark=none] table[x index=1,y index=0]  {\datatablec};
\end{groupplot}

% draw horizontal dashed lines
\draw [dashed] (a100) -- (3b);
\draw [dashed] (a55) -- (3a);

\end{tikzpicture}
\end{document}

相关内容