我想創建一個不連續的圖,可以在不連續縮放的情況下從 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}