tikz/pgfplots 忽略最后一列进行着色

tikz/pgfplots 忽略最后一列进行着色

我正在使用软件套件中的以下 tex 脚本,生成更大图的部分内容。它或多或少按预期工作,但有一个问题。由于我不是 PGF/TikZ 的常规用户,因此我很难找到错误。

这是给出下图的代码的重要部分。

\documentclass{standalone}
\usepackage{xcolor}
\usepackage{tikz, pgfplots}
\usetikzlibrary{plotmarks, arrows}
\usetikzlibrary{calc, decorations, plotmarks, fit, positioning, shapes.geometric}
\pgfplotsset{compat=1.4}

\begin{filecontents}{all.data}
    Header
    1    1SingNA  1.44700  0.05000
    2    2SingNA  1.56100  0.00000
    3    3SingNA  1.88500  0.23100
    4    4SingNA  2.06700  0.10800
    5    5SingNA  2.11000  0.20900
    6    6SingNA  2.18400  0.00300
    7    7SingNA  2.25500  0.04600
    8    8SingNA  2.29000  0.00000
    9    9SingNA  2.46900  0.21800
    10   10SingNA  2.50100  0.46700
    11   11SingNA  2.54300  0.00000
    12   12SingNA  2.62500  0.01000
    13   13SingNA  2.86200  0.13100
    14   14SingNA  2.92100  0.27300
\end{filecontents}

% settings for the coordinate system
\pgfplotsset{
    every linear axis/.append style={
        width=8.500 cm, height=2.0cm,xmin=0, xmax=15,
        scale only axis, axis on top,
        yticklabel style={
            /pgf/number format/fixed,
            /pgf/number format/zerofill,
            /pgf/number format/precision=1},
        legend style={at={(1.01,0.00)}, anchor=south west, draw=none, fill=black!5, inner sep=0.5pt, outer sep=0.5pt},
        legend columns=1, legend cell align=left},
}
\pgfplotsset{colormap={CI}{color=(black); color=(blue!50); color=(green!70);}}

% ===========================================================================

\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        anchor=south west, at={(0,0)},
        height=3.0cm,
        xlabel={}, ylabel={Energy (eV)},
        xtick={-10}, xticklabels={},
        colorbar % uncomment for colorbar as legend
        ]
        \addplot[mark=-, only marks, mark options={scale=2, line width=2pt}]  table[x index=0, y index=2] {all.data};

        \addplot+[solid, mesh, point meta=explicit, no markers, line width=5cm, shader=flat corner] table[x expr=\thisrowno{0}-0.5, y expr=2, meta index=3, meta expr=\thisrowno{3}] {all.data};
        % LABELING THE ACTUAL NUMBERS TO SHOW THAT THE COLUMN AT LEAST IS THERE
        \addplot+[ybar, nodes near coords, point meta=explicit symbolic, no markers, xticklabel style={rotate=90}] table[x index=0, y index=3, meta index=3, meta expr=\thisrowno{3}] {all.data};
    \end{axis}

\end{tikzpicture}
\end{document}

我得到的是:

来自代码示例中的图像,最后一列颜色为白色而不是蓝色

每列的条形图根据外部文件中的值着色,但最后一列没有着色。

我想要的是:

我还希望最后一列能够根据来自外部文件的值进行着色。

答案1

这基本上是一个扩展的评论。信息是,可能存在比使用具有巨大线宽的 1D 网格图更好的方法来实现您的目标。示例包括“从顶部”查看的 3D 网格图或(滥用)使用绘图标记来获取这些条形图。这是一个例子,但请注意这不是最终的绘图。(我改编了来自您的评论的版本因为这似乎更接近你想要的。)

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

\begin{filecontents}{all.data}
    Header
    1    1SingNA  1.44700  0.05000
    2    2SingNA  1.56100  0.00000
    3    3SingNA  1.88500  0.23100
    4    4SingNA  2.06700  0.10800
    5    5SingNA  2.11000  0.20900
    6    6SingNA  2.18400  0.00300
    7    7SingNA  2.25500  0.04600
    8    8SingNA  2.29000  0.00000
    9    9SingNA  2.46900  0.21800
    10   10SingNA  2.50100  0.46700
    11   11SingNA  2.54300  0.00000
    12   12SingNA  2.62500  0.01000
    13   13SingNA  2.86200  0.13100
    14   14SingNA  2.92100  0.27300
\end{filecontents}

% settings for the coordinate system
\pgfplotsset{
    every linear axis/.append style={
        width=8.500 cm, height=2.0cm,xmin=0, xmax=15,
        scale only axis, axis on top,
        yticklabel style={
            /pgf/number format/fixed,
            /pgf/number format/zerofill,
            /pgf/number format/precision=1},
        legend style={at={(1.01,0.00)}, anchor=south west, draw=none, fill=black!5, inner sep=0.5pt, outer sep=0.5pt},
        legend columns=1, legend cell align=left},
}
\pgfplotsset{colormap={CI}{color=(black); color=(blue!50); color=(green!70);}}

% ===========================================================================

\begin{document}
\begin{tikzpicture}
\begin{axis}[clip marker paths,
    anchor=south west, at={(0,0)},
    height=3.0cm,
    xlabel={}, ylabel={Energy (eV)},
    xtick={-10}, xticklabels={},
    colorbar, % uncomment for colorbar as legend
    nodes near coords
    style={font=\footnotesize,text=white,rotate=90,anchor=west}
    ]
   \addplot[mark=-, only marks, mark options={scale=2, line width=2pt}]  table[x index=0, y index=2] {all.data};
% 
   \addplot[scatter,mark=square*, point meta=explicit,only marks, mark
        size=0.265cm, mark options={yscale=8}] table[x expr=\coordindex+1,y expr=2, meta
        index=3] {all.data};    
% LABELING THE ACTUAL NUMBERS TO SHOW THAT THE COLUMN AT LEAST IS THERE
  \addplot[ybar, nodes near coords, 
  %point meta=explicit symbolic, 
  no markers, xticklabel style={rotate=90}] 
  table[x index=0, y index=3, meta index=3] {all.data}; 
\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容