答案1
您可以使用colorbar
pgfplot 的 s 来实现这一点。此颜色条可在 pgfplots 手册 v1.16 的第 199 页找到。
\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}[font=\large\bfseries]
\begin{scope}
\clip(-0.1,-0.81) rectangle (6.1,0.01);
\pgfplotscolorbardrawstandalone[
colormap={hot}{
samples of colormap=(4)
},
colorbar horizontal,
colormap access=map,
]
\end{scope}
\path (6.25,0) node[above right] {position 1} (0,0) node[above] {position 2}
(3,-1) node[below] {title};
\end{tikzpicture}
\end{document}
如果你不想剪辑,你可以这样做
\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}[font=\large\bfseries]
\pgfplotscolorbardrawstandalone[
colormap={hot}{
samples of colormap=(3)
},
colorbar horizontal,
colormap access=map,
xticklabel style={opacity=0,overlay}
]
\path (6.25,0) node[above right] {position 1} (0,0) node[above] {position 2}
(3,-1) node[below] {title};
\end{tikzpicture}
\end{document}
这导致了同样的结果。