Volume slices with multiple colormaps

I would like to be able to plot multiple slices in one figure where each slice can have its own colormap and clims set. The purpose is to be able to plot mulitple quantities (such as fluid velocity and pressure) where the value ranges may not coincide.
I have tried to link two axes as suggested in the answer for this question. However, that solution doesn't handle occlusion very well as shown below.
load wind;
ax1 = gca;
s1 = slice(x, y, z, u, 100, [], 10);
ax2 = axes;
s2 = slice(x, y, z, 100*u, [], 40, []);
ax2.Visible = 'off';
colormap(ax2, 'jet');
linked_properties = {'CameraPosition', 'CameraUpVector',...
'PlotBoxAspectRatio', 'CameraTarget', 'XLim', 'YLim', 'ZLim',...
'DataAspectRatio', 'Position'};
hlink = linkprop([ax1,ax2], linked_properties);
view(145, 30);
Plotting all the slices on one axes fixes the occlusion issue but can only use a single colormap and clim as shown below.
Is this something that can be solved in MATLAB or is it just one of those quirks that you need to live with?

8 Comments

Adam Danz
Adam Danz on 3 Jun 2021
Edited: Adam Danz on 3 Jun 2021
Axis overlays don't work with 3D plots with surfaces that intersect.
The only thing I can think of is rescaling the u/v values so their differences are smaller but still have a separation between max(u) and min(v) and then changing the colorbar ticks and ticklabels to stop the jump in values between u and v. It's a solid chunk of work and will only work if you can rescale the values of u or v without overlapping them.
Or you could just plot the two slice plots on different axes which is the easiest solution.
I agree that plotting on different axes (with subplot) is the easist solution. That just won't work for what I want.
I was able to get something to sort of work by setting the CData property in a call to surface. That requires manually indexing into a colormap array and using the low level surface instead of slice but it sort of works.
freezeColors() from the File Exchange.
Good idea.
This comment may be helpful. It maps rows of a colormap onto line segments based on a vector of z-values. It's fairly straightforward and you've probably already figured out how to do that.
Good call, @Walter Roberson, I didn't know about that one. Tested it....
load wind;
ax1 = gca;
colormap('parula')
s1 = slice(x, y, z, u, 100, [], 10);
hold on
freezeColors(ax1)
colormap('hot')
s2 = slice(x, y, z, 100*u, [], 40, []);
The colorbar will only represent the last colormap, though. The documentation in freezeColors referrs to another file exchange function to handle that (not tested).
The freezeColors function seems like it works for me. As long as you don't need more than two colormaps (and it could probably be modified to support that too). The colorbar freeze function that's linked in the documentation doesn't seem to work anymore though. But that's getting off topic.

Sign in to comment.

Answers (0)

Products

Release

R2020a

Asked:

on 3 Jun 2021

Commented:

on 3 Jun 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!