I'm using pgfplots in latex to create a colorbar next to some existing images which uses a custom colormap. The issues I'm facing are:
- xticklabels are getting inside the colorbar (see image below). When I use compat flag, my colorbar vanishes. Hence, I have commented it out.
- How do I get a title above the colorbar? The way I do it, it creates that space.
- Also can I remove the xticklines?
Please see the MWE below:
\documentclass{article}
\usepackage{pgfplots}
\usepackage{tikz}
%\pgfplotsset{compat=1.17}
\usepgfplotslibrary{colormaps}
\pgfplotsset{
colormap/plasma/.style={%
/pgfplots/colormap={plasma}{%
rgb=(0.050383, 0.029803, 0.527975)
rgb=(0.186213, 0.018803, 0.587228)
rgb=(0.287076, 0.010855, 0.627295)
rgb=(0.381047, 0.001814, 0.653068)
rgb=(0.471457, 0.005678, 0.659897)
rgb=(0.557243, 0.047331, 0.643443)
rgb=(0.636008, 0.112092, 0.605205)
rgb=(0.706178, 0.178437, 0.553657)
rgb=(0.768090, 0.244817, 0.498465)
rgb=(0.823132, 0.311261, 0.444806)
rgb=(0.872303, 0.378774, 0.393355)
rgb=(0.915471, 0.448807, 0.342890)
rgb=(0.951344, 0.522850, 0.292275)
rgb=(0.977856, 0.602051, 0.241387)
rgb=(0.992541, 0.687030, 0.192170)
rgb=(0.992505, 0.777967, 0.152855)
rgb=(0.974443, 0.874622, 0.144061)
rgb=(0.940015, 0.975158, 0.131326)
},
},
}
\begin{document}
\begin{figure*}
\centering
\begin{tabular}{cccc}
\begin{subfigure}[b]{0.25\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image}
\caption{Image A}
\end{subfigure}
& \hfill
\begin{subfigure}[b]{0.25\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image}
\caption{Image B}
\end{subfigure}
& \hfill
\begin{subfigure}[b]{0.25\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image}
\caption{Image C}
\end{subfigure}
&
\begin{tikzpicture}
\begin{axis}[
hide axis,
scale only axis,
height=0pt,
width=0pt,
colormap/plasma,
colorbar horizontal,
point meta min=0,
point meta max=25,
colorbar style={
width=3cm,
rotate=90,
xtick={0,5,10,15,20,25},
title=Colormap Title,
}
]
\addplot [draw=none] coordinates {(0,0) (1,1)};
\end{axis}
\end{tikzpicture}
\end{tabular}
\caption{\textbf{Image}}
\end{figure*}