获取轴和颜色条的边界框

获取轴和颜色条的边界框

我想将我的中心置于和legend上方,但找不到正确的边界框。axiscolorbar

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}

\pgfplotstableread{
x y z
5 5 1
6 6 2
7 7 3
8 8 4
}\mytable

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    colorbar,
    colorbar style={ytick={1,2,3,4},ylabel={z}},
    legend style={at={(current bounding box.north)},anchor={south}}
]

\addplot [scatter,scatter src=\thisrow{z},only marks,mark=*] table {\mytable};

\legend{loooooooooooooooooooooooooong entry}

\end{axis}
\end{tikzpicture}

\end{document}

答案1

怎么样

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}

\pgfplotstableread{
x y z
5 5 1
6 6 2
7 7 3
8 8 4
}\mytable

\begin{document}

\begin{tikzpicture}
\begin{scope}[local bounding box=plot]
\begin{axis}[legend to name=named,
    colorbar,
    colorbar style={ytick={1,2,3,4},ylabel={z}},
   % legend style={at={(current bounding box.north)},anchor={south}}
]

\addplot [scatter,scatter src=\thisrow{z},only marks,mark=*] table {\mytable};

\legend{loooooooooooooooooooooooooong entry}

\end{axis}
\end{scope}
\node[anchor=south] at (plot.north) {\ref{named}};
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容