下面是一個MWE
\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\usetikzlibrary{pgfplots.groupplots}
\pgfplotsset{compat = 1.12}
\begin{document}
\centering
\begin{figure}
\centering
\begin{tikzpicture}{fig6}
\begin{groupplot}[
height=6cm,
width=6cm,
group style={group size=2 by 2,
group name = fig6_plots,
xlabels at=edge bottom,
ylabels at=edge left
},
xlabel = {\footnotesize $\rho$},
ylabel = {\footnotesize $\gamma$},
colorbar horizontal,
colorbar to name=Fig6Colorbar,
colormap/blackwhite,
y tick label style={
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=2,
/tikz/.cd
},
x tick label style={
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=0,
/tikz/.cd
}]
\nextgroupplot[title={\scriptsize Increasing $\alpha$}, z buffer=sort]
\addplot3[surf, shader=interp,colormap/blackwhite] file {PlusIncreasingSurface.txt};
\nextgroupplot[title={\scriptsize Decreasing $\alpha$}, z buffer=sort]
\addplot3[surf, shader=interp,colormap/blackwhite] file {PlusDecreasingSurface.txt};
\nextgroupplot[title={\scriptsize Delta from Come and Go},view={0}{90}]
\addplot3[surf, shader=interp,point meta min=-10,point meta max=0] file {PlusIncreasingDeltaSurface.txt};
\nextgroupplot[title={\scriptsize Delta from Come and Go},view={0}{90}]
\addplot3[surf, shader=interp,point meta min=-10,point meta max=0] file {PlusDecreasingDeltaSurface.txt};
\end{groupplot}
\node (fig6_Legend) at ($(fig6_plots c1r2.center)!0.5!(fig6_plots c2r2.center)-(0,4.5cm)$){\ref{Fig6Colorbar}};
\end{tikzpicture}
\caption{+Resources Reactive with $\alpha$ Starting at Upper Bound}
\label{ReactiveDecreasing}
\end{figure}
\end{document}
產生這個輸出
當使用此處連結的數據文件運行時
PlusIncreasingDeltaSurface.txt
PlusDecreasingDeltaSurface.txt
到目前為止一切都很好......但考慮到比例上的巨大差異,我決定放棄組合色條並讓每個底部圖表都有自己的比例。因此,我註解掉了有關生成組合色條的節點和元點的部分,留下了
\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\usetikzlibrary{pgfplots.groupplots}
\pgfplotsset{compat = 1.12}
\begin{document}
\centering
\begin{figure}
\centering
\begin{tikzpicture}{fig6}
\begin{groupplot}[
height=6cm,
width=6cm,
group style={group size=2 by 2,
group name = fig6_plots,
xlabels at=edge bottom,
ylabels at=edge left
},
xlabel = {\footnotesize $\rho$},
ylabel = {\footnotesize $\gamma$},
colorbar horizontal,
%colorbar to name=Fig6Colorbar,
colormap/blackwhite,
y tick label style={
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=2,
/tikz/.cd
},
x tick label style={
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=0,
/tikz/.cd
}]
\nextgroupplot[title={\scriptsize Increasing $\alpha$}, z buffer=sort]
\addplot3[surf, shader=interp,colormap/blackwhite] file {PlusIncreasingSurface.txt};
\nextgroupplot[title={\scriptsize Decreasing $\alpha$}, z buffer=sort]
\addplot3[surf, shader=interp,colormap/blackwhite] file {PlusDecreasingSurface.txt};
\nextgroupplot[title={\scriptsize Delta from Come and Go},view={0}{90}]
%\addplot3[surf, shader=interp,point meta min=-10,point meta max=0] file {PlusIncreasingDeltaSurface.txt};
\addplot3[surf, shader=interp] file {PlusIncreasingDeltaSurface.txt};
\nextgroupplot[title={\scriptsize Delta from Come and Go},view={0}{90}]
%\addplot3[surf, shader=interp,point meta min=-10,point meta max=0] file {PlusDecreasingDeltaSurface.txt};
\addplot3[surf, shader=interp] file {PlusDecreasingDeltaSurface.txt};
\end{groupplot}
%\node (fig6_Legend) at ($(fig6_plots c1r2.center)!0.5!(fig6_plots c2r2.center)-(0,4.5cm)$){\ref{Fig6Colorbar}};
\end{tikzpicture}
\caption{+Resources Reactive with $\alpha$ Starting at Upper Bound}
\label{ReactiveDecreasing}
\end{figure}
\end{document}
當我在相同的數據上運行這個時,我現在得到了這個
兩個等值線圖頂部的「切片」是怎麼回事?看起來每個圖的頂部都有一個未標記的色條?
額外問題 - 如何更改色條中刻度的精確度?
答案1
您在兩個等高線圖頂部看到的“切片”實際上是最上面兩個圖的色條。當您新增colorbar horizontal
到整個群組時,這些內容就會包含在內。每個axis
環境都會繼承這些選項,意思是每一個該組中的繪圖將有自己的色條。為了清楚地看到這一點,您可以增加圖之間的垂直間距。
為了避免這種情況,您必須將選項移到colorbar horizontal
您確實需要的軸上。如果您希望兩個等值線圖的色條具有相同的刻度格式,您可以簡單地在 中建立一個新樣式pgfplots
,並將其套用到這些軸。如果你寫
\pgfplotsset{%
mycolorbar/.style={%
colorbar horizontal,
every colorbar/.append style={%
x tick label style={%
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=2,
/tikz/.cd}}}
}
前環境tikzpicture
中,您只需將選項新增mycolorbar
至您想要色條的軸即可。如果您希望兩個色條具有不同的格式,則必須在每個\nextgroupplot[...]
選項中定義它們。
因此,以下程式碼給出了以下輸出
\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\usetikzlibrary{pgfplots.groupplots}
\pgfplotsset{compat = 1.12}
\begin{document}
\pgfplotsset{%
mycolorbar/.style={%
colorbar horizontal,
every colorbar/.append style={%
x tick label style={%
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=2,
/tikz/.cd}}}
}
\begin{figure}
\centering
\begin{tikzpicture}{fig6}
\begin{groupplot}[
height=6cm,
width=6cm,
group style={%
group size=2 by 2,
group name=fig6_plots,
xlabels at=edge bottom,
ylabels at=edge left
},
xlabel = {\footnotesize $\rho$},
ylabel = {\footnotesize $\gamma$},
%colorbar to name=Fig6Colorbar,
colormap/blackwhite,
y tick label style={%
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=2,
/tikz/.cd
},
x tick label style={
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=0,
/tikz/.cd
}
]
\nextgroupplot[title={\scriptsize Increasing $\alpha$}, z buffer=sort]
\addplot3[surf, shader=interp,colormap/blackwhite] file {PlusIncreasingSurface.txt};
\nextgroupplot[title={\scriptsize Decreasing $\alpha$}, z buffer=sort]
\addplot3[surf, shader=interp,colormap/blackwhite] file {PlusDecreasingSurface.txt};
\nextgroupplot[mycolorbar, title={\scriptsize Delta from Come and Go},view={0}{90}]
\addplot3[surf, shader=interp] file {PlusIncreasingDeltaSurface.txt};
\nextgroupplot[mycolorbar, title={\scriptsize Delta from Come and Go},view={0}{90}]
\addplot3[surf, shader=interp] file {PlusDecreasingDeltaSurface.txt};
\end{groupplot}
\end{tikzpicture}
\caption{+Resources Reactive with $\alpha$ Starting at Upper Bound}
\label{ReactiveDecreasing}
\end{figure}
\end{document}