latex 中 pgfplot 的 colorbar 问题

latex 中 pgfplot 的 colorbar 问题

我正在使用 latex 中的 pgfplots 在一些使用自定义颜色图的现有图像旁边创建一个颜色条。我面临的问题是:

  1. xticklabels 进入了颜色栏(见下图)。当我使用 compat 标志时,颜色栏消失了。因此,我已将其注释掉。
  2. 如何在颜色栏上方添加标题?我这样做会创建该空间。
  3. 另外,我可以删除 xticklines 吗?

请参阅下面的 MWE:

  \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*}

在此处输入图片描述

答案1

发生此问题的原因是您正在旋转水平颜色条。如果您已经有了绘图,则可以使用colorbar right而不是colorbar horizontal。否则,您可以坚持使用现有代码并更改xticklabelxticktitle样式。

  1. 使用以下方法移动 xtick 标签:xticklabel style={xshift=10pt,yshift=5pt},
  2. 使用以下方法删除刻度标记:xtick style={draw=none},
  3. 转移标题 -title style={xshift=2.5cm,yshift=3.2cm},

输出: 在此处输入图片描述

代码:

 \documentclass{article}
  \usepackage{pgfplots}
  \usepackage{tikz}
  %\pgfplotsset{compat=1.17}
  \usepgfplotslibrary{colormaps}
  \usepackage{subcaption}
  
  \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}[rotate=0]
     \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,
            title=Colormap Title,
            xtick={0,5,10,15,20,25},
            xtick style={draw=none},
            xticklabel style={xshift=10pt,yshift=5pt},
            title style={xshift=2.5cm,yshift=3.2cm},
        }
      ]
        \addplot [draw=none] coordinates {(0,0) (1,1)};
      \end{axis}
     \end{tikzpicture}
\end{tabular}
        \caption{\textbf{Image}}
\end{figure*}
\end{document}

相关内容