image thumbnail

Generating surface plot with bars at specific (x,y) points

by

 

This function generates mesh plot with 3Dbars at specific (x,y) points by using fill3 function.

To generate a mesh plot with bars at specific (x,y) points

To generate a mesh plot with bars at specific (x,y) points

function mesh_with_3Dbars(xMin,xMax,yMin,yMax,cMax,zMax,zMin)
if nargin==0
    xMin=0;
    xMax=10;
    yMin=0;
    yMax=10;
    zMax=10;
    zMin=0;
    cMax=0.8;
end
% The value of cMax needs to be chnaged
xLoc=0.25*xMax; % starting x-location
yLoc=0.35*yMax; % starting y-location
dw=0.05; % width of bars
hFig=figure;
bars3D(xLoc,yLoc,dw,zMax,zMin,cMax);
dataX=0.95*zMax*(1-0.05*rand(20,20));
set(gca,'XLim',[xMin xMax],'YLim',[yMin yMax],'ZLim',[zMin zMax]);
xi=xMax/20:xMax/20:xMax;
yi=yMax/20:yMax/20:yMax;
surf(xi,yi,dataX);
xlabel('x');
ylabel('y');
zlabel('Variable of interest');


for xLoc=[0.5 0.3 0.4 0.65 0.3 0.4]*xMax;
    for yLoc=[0.75 0.3 0.4 0.6 0.85 0.3]*yMax;
        bars3D(xLoc,yLoc,dw,zMax,zMin,cMax);
    end
end
% Create textarrow
annotation(hFig,'textarrow',[0.160714285714286 0.258928571428571],...
    [0.622809523809524 0.692857142857143],'TextEdgeColor','none',...
    'String',{'mesh'});

% Create textarrow
annotation(hFig,'textarrow',[0.223214285714286 0.316071428571429],...
    [0.403761904761905 0.428571428571429],'TextEdgeColor','none',...
    'String',{'bar'});

figF='FigMesh_3Dbars.eps';
print('-depsc2',figF);

function bars3D(xLoc,yLoc,dw,zMax,zMin,cMax)
X = [xLoc+0 xLoc+0 xLoc+0 xLoc+0];
Y = [yLoc+0 yLoc+0 yLoc+dw yLoc+dw];
Z = [zMin zMax zMax zMin];
C = ones(size(X))*cMax;
fill3(X,Y,Z,C);
grid('on');
hold('on');
X = [xLoc+dw xLoc+dw xLoc+dw xLoc+dw];
Y = [yLoc+0 yLoc+0 yLoc+dw yLoc+dw];
Z = [zMin zMax zMax zMin];
C = ones(size(X))*cMax;
fill3(X,Y,Z,C);
X = [xLoc+0 xLoc+dw xLoc+dw xLoc+0];
Y = [yLoc+0 yLoc+0 yLoc+0 yLoc+0];
Z = [zMin zMin zMax zMax];
C = ones(size(X))*cMax;
fill3(X,Y,Z,C);
X = [xLoc+0 xLoc+dw xLoc+dw xLoc+0];
Y = [yLoc+dw yLoc+dw yLoc+dw yLoc+dw];
Z = [zMin zMin zMax zMax];
C = ones(size(X))*cMax;
fill3(X,Y,Z,C);

Contact us