# plotting a multivariable function by colors

3 views (last 30 days)
Hamed Pouria on 18 Aug 2019
Edited: Rik on 21 Aug 2019
Hello.
I want to plot this picture bot I don't know what command to useand how.

Rik on 18 Aug 2019
Edited: Rik on 21 Aug 2019
You can use the surf function (and set the view so you look from above), or use ind2rgb to apply a colormap.
Edit:
The code below should give you an idea of how to get your desired result.
%retrieve the x,y,z information from the surf
f=openfig('1.fig');
ax=findobj(get(f,'Children'),'type','axes');
S=findobj(get(ax,'Children'),'type','Surface');
x=get(S,'XData');
y=get(S,'YData');
z=get(S,'ZData');
z_backup=z;
close all%close all currently opened figures (use only during debugging)
%% option 1: using surf
%replace inf and -inf by edge values for a more pretty plot
z(isinf(z) & z>0)=max(z(~isinf(z)));
z(isinf(z) & z<0)=min(z(~isinf(z)));
figure
surf(x,y,z,'EdgeColor','none')
view(0,90)
axis([min(x) max(x) min(y) max(y)])
%% option 2: using ind2rgb
%define a colormap
map=colormap('hot');
z=z_backup;%restore z
%scale z-data so it is an indexed image
L=~( isinf(z(:)) | isnan(z(:)) );
range=[min(z(L)) max(z(L))];
z=(z-range(1))/(range(2)-range(1));
z=ceil(z*size(map,1));
IM=ind2rgb(z,map);
IM=rot90(IM,2);%account for different directional convention
%show image
figure
imshow(IM)

#### 1 Comment

Hamed Pouria on 21 Aug 2019
Thank you so much. I used surf and I got this. (still has difference)