How to plot two isosurfaces in one figure?

16 views (last 30 days)
I want to overlap two figures. and see cross section. And the colorbars of two figures have different color range.
isovalues1 = 0:0.1:1;
for i=1:length(isovalues1)
isosurface(X,Y,Z,Z1,isovalues1(i));
end
ax(1)=gca;
hc(1,1)=colorbar;
hc(1,1).Limits = [0 1];
ax(2)=axes;
set(gca, 'Color', 'none')
view(3)
isovalues2 = 40:10:100;
for i=1:length(isovalues2)
isosurface(X,Y,Z,Z2,isovalues2(i));
end
alpha(.5)
set(ax(2), 'XAxisLocation','top',...
'YAxisLocation','right',...
'Color','none');
hc(1,2)=colorbar;
hc(1,2).Limits = [40 100];
but when I plot figures like above, second figure is just plotted on the first figure. How can I fix it?

Accepted Answer

Nick Counts
Nick Counts on 5 Nov 2016
Edited: Nick Counts on 5 Nov 2016
Nayoung,
It looks like there are 3 issues here:
1. Plotting two surfaces on the same axes
You are explicitly asking for a second set of axes with
ax(2)=axes;
Remove that line, add
hold on;
and fix the reference to ax(2):
set(ax(1), 'XAxisLocation','top',...
'YAxisLocation','right',...
'Color','none');
Hold on prevents plot functions from removing existing graphics from an axes. You should probably be using it inside your for-loops.
See Walter's answer to your previous question.
2. Using two colorbars on the same axes
Two colorbars is not supported. You may be able to define individual color maps for your surfaces to help you differentiate them.
There is a lot of good information here, along with example code: How do I use multiple colormaps in a single figure?
3. Finding a cross-section of two surfaces
To find a cross-section or intersection you would need to do some additional math (solve for the thing you want to see) and then plot that data. I am not aware of any 'cross section viewing' tools built in to Matlab's plotting engine.
I lied, I thought of a 4th thing:
4. isosurface in a loop?
This may be what you are intending to do, as I do not understand what your data/variables are modeling and what you are trying to visualize. Realize that you are plotting a surface for each value of both isovalues1 and isovalues2, which means 16 surfaces total, not the two you described in the question title.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!