我想创建一个非连续图,其中可以从 10%“跳”到 50%,而无需连续缩放。我想我自己找到了大部分解决方案,并将在下面发布。“问题”是我无法将第一个图组定义为,ymin=0,ymax=6,
将第二个图组定义为ymin=45,ymax=80,
。当我定义第一个范围时,它会将图的这一部分移到最右侧,并将其中的一部分移出图(我不明白为什么)。看这张图片:
当我定义第二个范围时,图表只是“消失”,并且文档的这一部分只剩下一个空白。
目前看起来像这样: 这几乎就是我想要显示的内容,只是我想在图表的“底部”右侧只显示 4 个具有“相同”高度的条形图,因为它们在上部和左下部有所不同,因此实际上可以看到条形图的不同高度,而不是像当前的样子。当然,在上部,左侧条形图不应显示,因为它们的值太小。
我希望你能帮助我解决这个问题
\documentclass{ifacconf}
\usepackage[round]{natbib}
\usepackage{graphicx}
\usepackage{pgfplots}
\usetikzlibrary{pgfplots.groupplots}
\usepackage{tikz-timing}
\usepackage{listings}
\usepackage{xcolor}
\definecolor{ForestGreen}{RGB}{34,139,34}
\definecolor{Gold}{RGB}{218,165,32}
\definecolor{MediumBlue}{RGB}{25,25,205}
\usepackage{capt-of}
\begin{document}
\pgfplotsset{
every non boxed x axis/.style={}
}
\begin{tikzpicture}
\begin{groupplot}[
group style={
group name=my fancy plots,
group size=1 by 2,
xticklabels at=edge bottom,
vertical sep=0pt
},
width=9.5cm, ybar,
enlarge
x limits=0.5,
%ylabel={\#participants},
symbolic x coords={\# Variables (\%),Pipeline Utilization (\%)}, %efficiency
xtick=data,
%nodes near coords,
%nodes near coords align={vertical},
%every node near coord/.append style={font=\small},
legend style={at={(0.25,0.69)},anchor=south, cells={align=left}}, ]
\nextgroupplot[%ymin=45,ymax=80,
ytick={60,80},
axis x line=top,
axis y discontinuity=crunch,
ybar,
bar width=.68cm,
nodes near coords,
nodes near coords align={vertical},
every node near coord/.append style={font=\small},
height=4.5cm]
\addplot [color=purple, fill = purple,]coordinates {(\# Variables (\%),5.14) (Pipeline Utilization (\%),62.05)};
\addplot [color=orange, fill = orange,]coordinates {(\# Variables (\%),4.91) (Pipeline Utilization (\%),63.53)};
\addplot [color=ForestGreen, fill = ForestGreen,]coordinates {(\# Variables (\%),0.27) (Pipeline Utilization (\%),65.51)};
\addplot [color=MediumBlue, fill = MediumBlue,]coordinates {(\# Variables (\%),0.33) (Pipeline Utilization (\%),66.75)};
\nextgroupplot[%ymin=0,ymax=6,
ytick={0},
axis x line=bottom,
ybar,
bar width=.68cm,
height=2.0cm]
\addplot [color=purple, fill = purple,]coordinates {(\# Variables (\%),5.14) (Pipeline Utilization (\%),62.05)};
\addplot [color=orange, fill = orange,]coordinates {(\# Variables (\%),4.91) (Pipeline Utilization (\%),63.53)};
\addplot [color=ForestGreen, fill = ForestGreen,]coordinates {(\# Variables (\%),0.27) (Pipeline Utilization (\%),65.51)};
\addplot [color=MediumBlue, fill = MediumBlue,]coordinates {(\# Variables (\%),0.33) (Pipeline Utilization (\%),66.75)};
\end{groupplot}
\end{tikzpicture}
\end{document}
答案1
我认为,您的方法更适合折线图,但不适合柱状图。
您可以使用两个具有不同比例的轴:
\documentclass{article}
\usepackage[round]{natbib}
\usepackage{graphicx}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usetikzlibrary{pgfplots.groupplots}
\usepackage{tikz-timing}
\usepackage{listings}
\usepackage{xcolor}
\definecolor{ForestGreen}{RGB}{34,139,34}
\definecolor{Gold}{RGB}{218,165,32}
\definecolor{MediumBlue}{RGB}{25,25,205}
\usepackage{capt-of}
\begin{document}
\begin{tikzpicture}
\pgfplotsset{
width=95mm,
axis x line=box,
axis y discontinuity=crunch,
ybar,
xmin=0,xmax=1,
xtick={0,1},
xticklabels={\# Variables (\%),Pipeline Utilization (\%)},
enlarge x limits=.5,
}
\begin{axis}[%
ymin=45, ymax=80,
height=45mm,
bar width=.68cm,
ytick={60,80},
nodes near coords,
nodes near coords align={vertical},
every node near coord/.append style={font=\small}]
\addplot [color=purple, fill = purple,] coordinates {(1,62.05)};
\addplot [color=orange, fill = orange,] coordinates {(1,63.53)};
\addplot [color=ForestGreen, fill = ForestGreen,] coordinates {(1,65.51)};
\addplot [color=MediumBlue, fill = MediumBlue,] coordinates {(1,66.75)};
\end{axis}
\begin{axis}[%
ymin=0, ymax=6,
height=20mm,
bar width=.68cm,
ytick={0},
axis line style={draw=none},
xticklabels={,},
nodes near coords,
nodes near coords align={vertical},
every node near coord/.append style={font=\small}]
\addplot [color=purple, fill = purple,]coordinates {(0,5.14)};
\addplot [color=orange, fill = orange,]coordinates {(0,4.91)};
\addplot [color=ForestGreen, fill = ForestGreen,]coordinates {(0,0.27)};
\addplot [color=MediumBlue, fill = MediumBlue,]coordinates {(0,0.33)};
\end{axis}
\end{tikzpicture}
\end{document}
编辑:目前无法使用pgfplots
选项来转移不连续性。此外,当对轴应用装饰时似乎存在问题,尤其是使用pre length
和时post length
,如文档所述这里。不过,我还是设法使用替代轴的路径替换装饰绘制了自定义不连续性。遗憾的是,您似乎无法使用axis x line=box
此解决方案。
\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{decorations.pathreplacing}
\pgfplotsset{compat=1.14}
\usepackage{xcolor}
\definecolor{ForestGreen}{RGB}{34,139,34}
\definecolor{Gold}{RGB}{218,165,32}
\definecolor{MediumBlue}{RGB}{25,25,205}
\begin{document}
\begin{tikzpicture}[discontinuity/.style={decoration={show path construction,lineto code={%
\path (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast) coordinate[pos=.3] (mid);%
\draw (\tikzinputsegmentfirst) -- ([yshift=-6pt]mid) -- ++(-3pt,3pt) -- ++(6pt,3pt) -- ++(-3pt,3pt) -- (\tikzinputsegmentlast);%
}}}]
\pgfplotsset{
width=95mm,
axis x line=bottom,
%axis y discontinuity=crunch,
ybar,
xmin=0,xmax=1,
xtick={0,1},
xticklabels={\# Variables (\%),Pipeline Utilization (\%)},
enlarge x limits=.5,
}
\begin{axis}[%
ymin=45, ymax=80,
height=45mm,
bar width=.68cm,
ytick={60,80},
nodes near coords,
nodes near coords align={vertical},
every node near coord/.append style={font=\small},
every outer y axis line/.append style={discontinuity}
]
\addplot [color=purple, fill = purple,] coordinates {(1,62.05)};
\addplot [color=orange, fill = orange,] coordinates {(1,63.53)};
\addplot [color=ForestGreen, fill = ForestGreen,] coordinates {(1,65.51)};
\addplot [color=MediumBlue, fill = MediumBlue,] coordinates {(1,66.75)};
\end{axis}
\begin{axis}[%
ymin=0, ymax=6,
height=20mm,
bar width=.68cm,
ytick={0},
axis line style={draw=none},
tick style={draw=none},
xticklabels={,},
nodes near coords,
nodes near coords align={vertical},
every node near coord/.append style={font=\small}
]
\addplot [color=purple, fill = purple,]coordinates {(0,5.14)};
\addplot [color=orange, fill = orange,]coordinates {(0,4.91)};
\addplot [color=ForestGreen, fill = ForestGreen,]coordinates {(0,0.27)};
\addplot [color=MediumBlue, fill = MediumBlue,]coordinates {(0,0.33)};
\end{axis}
\end{tikzpicture}
\end{document}