两个具有统一颜色条的热图

两个具有统一颜色条的热图

我有 2 个热图,它们之间共享同一个颜色条。我想编辑颜色数量,并在颜色条中增加一些没有数字的额外刻度 - 这样每 2 个不同颜色之间就会有一个刻度。

我看到了各种解决方案,例如使用samples = ...、 或zmajorticks = falseztick = \empty

但是,它们都不起作用。也许是因为我没有该\axis命令,也不知道在哪里找到它,因为我有groupplot

以下是 MWE。提前致谢!

    \pgfplotsset{scaled x ticks=false}
    \pgfplotsset{scaled y ticks=false}

    \begin{tikzpicture}
      \begin{groupplot}[
          group style = {
            group size = 2 by 1,
            horizontal sep = 4cm,
          },
          view = {0}{90},
          /pgfplots/colormap={blackwhite}{gray(0cm)=(1);gray(1cm)=(0)},
          samples = 2,
        ]

          \nextgroupplot[
               xtick = {0, 0.005, 0.01},
               ytick = {0, 0.005, 0.01},
               xticklabels ={0, 0.005, 0.01},
               yticklabels ={0, 0.005, 0.01},
                colorbar left,
                colorbar style = {
                    samples = 2,
                    at={(rel axis cs: 1.3,0)},
                    anchor=south,
                    width=2mm,
                    view={0}{90},
                    zticklabels={0.5,0.55, 0.6, 0.65},
                }
                ]
                    \addplot3[
                        samples = 2,
                        surf,
                        shader=faceted,
                        point meta min=0.5,point meta max=0.66,
                    ]
      table[header=false] {
    0.0000 0.0000 0.5038
    0.0050 0.0000 0.5538
    0.0100 0.0000 0.6034
    0.0150 0.0000 0.6066

    0.0000 0.0050 0.5135
    0.0050 0.0050 0.5635
    0.0100 0.0050 0.6132
    0.0150 0.0050 0.6159

    0.0000 0.0100 0.5233
    0.0050 0.0100 0.5733
    0.0100 0.0100 0.6231
    0.0150 0.0100 0.6253

    0.0000 0.0150 0.5243
    0.0050 0.0150 0.5745
    0.0100 0.0150 0.6243
    0.0150 0.0150 0.6262

        };
          \nextgroupplot[
               xmin=0, xmax=0.015,
               ymin=0, ymax=0.015,
               xtick = {0, 0.005, 0.01},
               ytick = {0, 0.005, 0.01},
               xticklabels ={0, 0.005, 0.01},
               yticklabels ={0, 0.005, 0.01},
                 colorbar style = {
                    samples = 2,
                    at={(rel axis cs: 1.3,0)},
                    anchor=south,
                    width=2mm,
                  view={0}{90},
                 }
                ]
      \addplot3[
      surf,
      shader=faceted,
        point meta min=0.5,point meta max=0.72,
                samples = 2
      ]
      table[header=false] {
    0.0000 0.0000 0.5138
    0.0050 0.0000 0.5738
    0.0100 0.0000 0.6334
    0.0150 0.0000 0.6666

    0.0000 0.0050 0.5135
    0.0050 0.0050 0.5835
    0.0100 0.0050 0.6332
    0.0150 0.0050 0.6459

    0.0000 0.0100 0.5433
    0.0050 0.0100 0.5933
    0.0100 0.0100 0.6431
    0.0150 0.0100 0.6653

    0.0000 0.0150 0.5543
    0.0050 0.0150 0.5745
    0.0100 0.0150 0.6443
    0.0150 0.0150 0.6762
        };
      \end{groupplot}

    \end{tikzpicture}

答案1

你曾经想过类似的事情吗?下面的代码

对于不太简单的工作示例(下次,请尝试专注于主要问题),我将一些设置放在了整体 groupplot 命令中。但是,您的代码中缺少的只是“colorbar sampled”和“point meta min/max”命令。顺便说一句,您的方法只需要一个条形图 - 因此没有理由使用第二个条形图。

更新#1:扩展版本作为第一个问题的答案

\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}

\begin{document}

    \pgfplotsset{scaled x ticks=false}
    \pgfplotsset{scaled y ticks=false}
    \begin{tikzpicture}
    \begin{groupplot}[
    group style = {
        group size = 2 by 1,
        horizontal sep = 4cm,
    },
    samples = 2,
    view = {0}{90},
    xtick = {0, 0.005, 0.01},
    xticklabels ={0, 0.005, 0.01},
    yticklabels ={0, 0.005, 0.01},
    ytick = {0, 0.005, 0.01},
    /pgfplots/colormap={blackwhite}{gray(0cm)=(1);gray(1cm)=(0)},
    ]
    \nextgroupplot[
    colorbar left,
    colorbar sampled, % essential command
    colorbar style = {
        samples = 7,  % gives 6 color fields within the bar
        at={(rel axis cs: 1.3,0)},
        anchor=south,
        width=2mm,
        view={0}{90},
        point meta min=0.5,  % also
        point meta max=0.65, % important
        tick align=center,
        ytick={0.5,0.525,0.55,0.575,0.6,0.625,0.65}, % add specific ticks
        yticklabels={0.5,,0.55,,0.6,,0.65}, % do not give value to ticks
    }
    ] \addplot3[
    surf,
    point meta min=0.5,
    point meta max=0.66,
    ]
    table[header=false] {
        0.0000 0.0000 0.5038
        0.0050 0.0000 0.5538
        0.0100 0.0000 0.6034
        0.0150 0.0000 0.6066

        0.0000 0.0050 0.5135
        0.0050 0.0050 0.5635
        0.0100 0.0050 0.6132
        0.0150 0.0050 0.6159

        0.0000 0.0100 0.5233
        0.0050 0.0100 0.5733
        0.0100 0.0100 0.6231
        0.0150 0.0100 0.6253

        0.0000 0.0150 0.5243
        0.0050 0.0150 0.5745
        0.0100 0.0150 0.6243
        0.0150 0.0150 0.6262
    };
    \nextgroupplot
    \addplot3[
    surf,
    point meta min=0.5,
    point meta max=0.72,
    ]
    table[header=false] {
        0.0000 0.0000 0.5138
        0.0050 0.0000 0.5738
        0.0100 0.0000 0.6334
        0.0150 0.0000 0.6666

        0.0000 0.0050 0.5135
        0.0050 0.0050 0.5835
        0.0100 0.0050 0.6332
        0.0150 0.0050 0.6459

        0.0000 0.0100 0.5433
        0.0050 0.0100 0.5933
        0.0100 0.0100 0.6431
        0.0150 0.0100 0.6653

        0.0000 0.0150 0.5543
        0.0050 0.0150 0.5745
        0.0100 0.0150 0.6443
        0.0150 0.0150 0.6762
    };
    \end{groupplot}

    \end{tikzpicture}
\end{document}

相关内容