英文:
How to indicate a cropped colormap
问题
我有一个根据给定函数着色的曲面图。为了清晰起见,颜色映射并不包含函数的所有值,因此颜色映射在两端被“裁剪”。
我想向观众指示颜色映射是不完整的(“裁剪”),既在颜色条上,也在图上。
例如,以这个示例(MATLAB)为例:
clearvars; clc;
x = linspace(-2,2,100);
y = linspace(-2,2,100);
[X,Y] = meshgrid(x,y);
Z = exp(-X.^2 - Y.^2);
C = (X+0.5).^2 + Y.^2;
fig = figure(1);
ax = subplot(1,1,1);
s = surf(X,Y,Z,C,'EdgeAlpha',0.2);
colorbar(ax);
ax.CLim = [0, 1];
在这种情况下,我想指示大黄色区域不是恒定的1,而是大于1,同时不失去由于限制颜色比例尺而得到的蓝色区域的颜色分辨率。
我没有尝试特定的方法,因为我不知道如何解决这个问题。这不仅仅是一个编码问题(“如何编码这个?”),也是一个关于裁剪颜色映射的一般性问题(“我应该怎么做?”)。
非常感谢!
英文:
I have a surface plot colored by a given function. For clarity, the colormap does not contain all of the values of the function, so the colormap is "cropped" at the ends.
I want to indicate to the viewer that the colormap is incomplete ("cropped"), both on the colorbar itself and on the plot.
For example, take this example (MATLAB):
clearvars; clc;
x = linspace(-2,2,100);
y = linspace(-2,2,100);
[X,Y] = meshgrid(x,y);
Z = exp(-X.^2 - Y.^2);
C = (X+0.5).^2 + Y.^2;
fig = figure(1);
ax = subplot(1,1,1);
s = surf(X,Y,Z,C,'EdgeAlpha',0.2);
colorbar(ax);
ax.CLim = [0, 1];
In this case I want to indicate that the large yellow region is not constant 1, but larger than 1, without loosing the color resolution in the blue region I get from limiting the color scale.
I didn't try anything specific, since I have no idea how to approach this problem. This is not only a coding problem ("How to code that?"), but also a question in general on cropped colormaps ("What should I do at all?").
Thanks a lot!
答案1
得分: 6
在色标标签中,您可以添加一行最简单的信息:
%% 仅修改最后一个刻度标签
cb = colorbar(ax);
cb.TickLabels{end} = '>1'
这表示在该颜色级别上,数值为`>1`:
[![clipped colormap 01][1]][1]
如果您希望更加突出地显示,您还可以为所有被裁剪的数据(所有数据>1)添加一个“饱和”颜色:
%% 和/或为“裁剪”数据分配特定颜色
% 为裁剪的数据定义颜色
% clippedColor = [.2 .2 .2] ; % 非常深的灰色
% clippedColor = [.9 .9 .9] ; % 非常浅的灰色
clippedColor = [1 0 0] ; % 红色
% 检索当前的颜色映射
cmap = colormap(fig) ;
% 将所选颜色分配给裁剪数据的最后一个颜色
cmap(end,:) = clippedColor ;
% 在256色的颜色映射中,我们需要更改matlab的最后两种颜色
% 以在色标中绘制此最后一个颜色。在较小的颜色映射中,这将是不必要的
cmap(end-1,:) = clippedColor ;
% 将修改后的颜色映射分配给图形
colormap(fig,cmap)
以下是3个饱和颜色的示例。我倾向于选择浅色版本(例如浅灰色)因为它们会让我的眼睛分散注意力较少,但是它们在色标本身中更难以辨认,所以您可以选择对您更重要的部分:
[![clipped colormap, saturated][2]][2]
最后一点,如果饱和界面处的锯齿状分界线让您感到不适,您可以应用一些阴影来平滑它。运行:
shading interp
会给您一个平滑的图形:
[![clipped colormap final][3]][3]
[1]: https://i.stack.imgur.com/6CAJf.png
[2]: https://i.stack.imgur.com/Wamky.png
[3]: https://i.stack.imgur.com/CpFfV.png
英文:
The simplest information you can add in one line is on the colorbar label:
%% Only modify last tick label
cb = colorbar(ax);
cb.TickLabels{end} = '>1'
This indicates that at that level of color, the values are >1
:
If you want something more visually prominent, you can also add a "saturated" color for all the clipped data (all data >1):
%% and/or assign a specific color to "cropped" data
% Define a color for clipped data
% clippedColor = [.2 .2 .2] ; % very dark grey
% clippedColor = [.9 .9 .9] ; % very light grey
clippedColor = [1 0 0] ; % red
% Retrieve the current colormap
cmap = colormap(fig) ;
% Manually assign the last color to the chosen color for clipped data
cmap(end,:) = clippedColor ;
% on a 256 colors colormap, we need to change the last 2 colors for matlab
% to draw this last color in the colorbar. On a smaller colormap it
% wouldn't be necessary
cmap(end-1,:) = clippedColor ;
% Assign the modified colormap to the figure
colormap(fig,cmap)
Here are 3 examples of saturated color. I tend to prefer the light versions (light grey for example) because they distract my eyes less, however they are more difficult to make out in the colorbar itself so choose what's more important for you:
Last thing, if the jagged delineation at the saturation interface bothers you, you can apply some shading to smooth that out. Running:
shading interp
will give you a smooth figure:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论