我遵循的例子是pgfplots 中的轴断裂
然而,我发现你在绘图上得到了虚假的垂直空间
有什么方法可以移除它吗?它为什么在那里?
\documentclass[convert]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{pgfplots.groupplots}
\begin{document}
\pgfplotsset{every non boxed x axis/.style={}}
\fbox{\begin{tikzpicture}%
\begin{groupplot}[
group style={
group name=my fancy plots,
group size=1 by 2,
xticklabels at=edge bottom,
vertical sep=0pt
},
width=8.5cm,
xmin=-6, xmax=6
]%
%
\nextgroupplot[ymin=45,ymax=80,
ytick={60,80},
axis x line=top,
axis y discontinuity=parallel,
height=4.5cm]%
\addplot {x*0};%
\addplot {x^2+50};%
%
\nextgroupplot[ymin=0,ymax=5,
ytick={0},
axis x line=bottom,
height=2.0cm]%
\addplot {x*0};%
\addplot {x^2+50};%
\end{groupplot}%
\end{tikzpicture}}
\end{document}
答案1
我只想添加一次这些情节,但很可能我遗漏了一些东西。
\documentclass[convert,border=3.14mm]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{pgfplots.groupplots}
\begin{document}
\pgfplotsset{every non boxed x axis/.style={}}
\fbox{\begin{tikzpicture}%
\begin{groupplot}[
group style={
group name=my fancy plots,
group size=1 by 2,
xticklabels at=edge bottom,
vertical sep=0pt
},
width=8.5cm,
xmin=-6, xmax=6
]%
%
\nextgroupplot[ymin=45,ymax=80,
ytick={60,80},
axis x line=top,
axis y discontinuity=parallel,
height=4.5cm]%
%\addplot {x*0};%
\addplot[red,mark=square*] {x^2+50};%
%
\nextgroupplot[ymin=0,ymax=5,overlay,
ytick={0},
axis x line=bottom,
height=2cm]%
\addplot[blue,mark=*] {x*0};%
%\addplot {x^2+50};%
\end{groupplot}%
\path(current axis.south) -- ++(0,-0.5cm);
\end{tikzpicture}}
\end{document}
答案2
我的解决方案需要使用重复图来简化进一步的计算。我的解决方案是采取一种变通方法,类似于\useasboundingbox
@Henri Menke 建议的选项。
但是,对于我来说,边界框一开始就不起作用。我需要使用 重置边界框\pgfresetboundingbox\path (plot c1r1.outer north west) rectangle (plot c1r2.outer south east);
,其中plot
是组的名称, 是c1r1
组的命名约定。
\documentclass[convert]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{pgfplots.groupplots}
\begin{document}
\pgfplotsset{every non boxed x axis/.style={}}
\fbox{\begin{tikzpicture}[]%
\begin{groupplot}[
group style={
group name=plot,
group size=1 by 2,
xticklabels at=edge bottom,
vertical sep=0pt
},
width=8.5cm,
xmin=-6, xmax=6
]%
%
\nextgroupplot[ymin=45,ymax=80,
ytick={60,80},
axis x line=top,
axis y discontinuity=parallel,
height=4.5cm,
legend to name=leg
]%
\addplot {x*0};%
\addplot {x^2+50};%
\nextgroupplot[ymin=0,ymax=5,
ytick={0},
axis x line=bottom,
height=2.0cm,
legend to name=leg
]%
\addplot {x*0};
\addplot {x^2+50};%
\end{groupplot}%
\pgfresetboundingbox\path (plot c1r1.outer north west) rectangle (plot c1r2.outer south east); % adjust to fit
\end{tikzpicture}}
\end{document}