Yoa*_*ack 4 matlab visualization surface colorbar 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];
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我想表明大黄色区域不是恒定的 1,而是大于 1,而不会丢失通过限制色标获得的蓝色区域的颜色分辨率。
我没有尝试任何具体的事情,因为我不知道如何解决这个问题。这不仅是一个编码问题(“如何编码?”),而且也是一个关于裁剪颜色图的一般问题(“我到底应该做什么?”)。
多谢!
您可以在一行中添加的最简单的信息位于颜色条标签上:
%% Only modify last tick label
cb = colorbar(ax);
cb.TickLabels{end} = '>1'
Run Code Online (Sandbox Code Playgroud)
这表明在该颜色级别,值为>1:
如果您想要视觉上更突出的东西,您还可以为所有剪辑的数据添加“饱和”颜色(所有数据> 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)
Run Code Online (Sandbox Code Playgroud)
以下是 3 个饱和颜色的示例。我倾向于更喜欢浅色版本(例如浅灰色),因为它们较少分散我的眼睛,但是它们在颜色条本身中更难以辨认,因此请选择对您更重要的颜色:
最后一件事,如果饱和界面处的锯齿状轮廓让您感到困扰,您可以应用一些阴影来平滑它。跑步:
shading interp
Run Code Online (Sandbox Code Playgroud)
会给你一个平滑的图形: