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

要得到

在此輸入影像描述

相關內容