pfg 轴不连续选项

pfg 轴不连续选项

有没有办法设置 x 轴上不连续的长度?这是我使用的代码:

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
  thick,
    black,%Set the color of the main axes and numbers
    scale=0.389,
    axis lines=left,
    xmin=200,
    xmax=350,
    ymin=0,
    ymax=3,
    major tick length=1.5pt,
    minor tick length=1pt,
    tick align = inside,
    axis x discontinuity=crunch,
    legend cell align={left},
    legend style={anchor=north, draw=none},
    label style={font=\tiny},
    tick label style={font=\tiny},
] 
\end{axis}
\end{tikzpicture}
\end{document}

该图形如下所示,不连续标记占据了几乎一个单位。

在此处输入图片描述

我想要一个更短的不连续标记,就像下图中的那样。

谢谢您的帮助!

在此处输入图片描述

答案1

这是一种可能解决方案。我不知道是否有更好的解决方案。

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\makeatletter
\def\pgfplots@drawaxis@lines@preparediscont@for#1{%
        \ifnum\csname pgfplots@#1axisdiscontnum\endcsname>0
                \begingroup
                % this group employs several temporary dimension registers
                % and is therefor scoped:
                \let\disstart=\pgf@ya
                \let\disend=\pgf@yb
                \disend=\csname pgfplots@#1max@reg\endcsname
                \advance\disend by -\csname pgfplots@#1min@reg\endcsname
                \disend=\csname pgfplots@#1@veclength\endcsname\disend
                \ifcase\csname pgfplots@#1axisdiscontnum\endcsname\relax
                        % has already been checked above.
                \or
                        \def\discontstyle{decoration={zigzag,segment length=8pt, amplitude=3pt}}%
                        \advance \disend by -12pt
                \or
                        \def\discontstyle{decoration={ticks,segment length=4pt, amplitude=8pt}}%
                        \advance \disend by -8pt
                \fi
                \pgfplotscoordmath{#1}{datascaletrafo get params}%
                % if #1max + shift < 0pt  (shift is 0 without the scaling trafo)
                \ifdim\csname pgfplots@#1max@reg\endcsname<-\pgfplotsretvalb pt
                        % swap start and end
                        \disstart=\disend
                        \disend=4pt
                \else
                        \disstart=4pt
                \fi
                % carry local computations outside of group:
                \xdef\pgfplots@glob@TMPa{%
                        \noexpand\def\expandafter\noexpand\csname #1disstart\endcsname{\the\disstart}%
                        \noexpand\def\expandafter\noexpand\csname #1disend\endcsname{\the\disend}%
                        \noexpand\pgfkeysdef{/tikz/#1discont}{\noexpand\pgfkeysalso{\discontstyle}}%
                }%
                \endgroup
                \pgfplots@glob@TMPa
        \else
                \expandafter\def\csname #1disstart\endcsname{0pt}%
                \expandafter\def\csname #1disend\endcsname{0pt}%
                \pgfkeyslet{/tikz/#1discont}=\pgfutil@empty
        \fi
}%
\makeatother
\begin{document}
\begin{tikzpicture}
\begin{axis}[
  thick,
    black,%Set the color of the main axes and numbers
    scale=0.389,
    axis lines=left,
    xmin=200,
    xmax=350,
    ymin=0,
    ymax=3,
    major tick length=1.5pt,
    minor tick length=1pt,
    tick align = inside,
    axis x discontinuity=crunch,
    legend cell align={left},
    legend style={anchor=north, draw=none},
    label style={font=\tiny},
    tick label style={font=\tiny},
] 
\end{axis}
\end{tikzpicture}
\end{document}

我变了

\def\discontstyle{decoration={zigzag,segment length=8pt, amplitude=3pt}}%
\advance \disend by -12pt

最初是在pgfplots.code.tex

\def\discontstyle{decoration={zigzag,segment length=12pt, amplitude=4pt}}%
\advance \disend by -16pt

要得到

在此处输入图片描述

相关内容