4

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];

A gaussian surface plot colored according to the two dimensional function f(x,y)=(x+0.5)^2+y^2, with a colorbar limited at 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!

DeadlosZ
  • 165
  • 5
  • In fluorescence microscopy it is common to show the acquired grayscale image with the 0 pixels (underexposed) painted blue and the 255 pixels (overexposed) painted red. You could do a similar thing by making the highest colormap element red instead of yellow. You'd have a smooth transition from blue to yellow through green and orange, as you do now, but then the part of the function with a value of 1 or larger would be painted red. – Cris Luengo Jun 29 '23 at 06:40
  • One way is to create an arrow at the "extended" end of the color map, like this: https://i.stack.imgur.com/ZrQpY.png (not sure how to do that in Matlab) – Aziz Jun 29 '23 at 06:42

1 Answers1

6

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:

clipped colormap 01

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:

clipped colormap, saturated

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:

clipped colormap final

Hoki
  • 11,637
  • 1
  • 24
  • 43