MATLAB: How to change the size of the bars

3d-barsbarschangechange sizegraphx axisy axis

I am trying to to change the size of the 3D bars accordingly to this figur (file name: "what I want.png"). Is it even possible to do that? I have been trying, but I don't know how to do it. My attempt so far its attached the file "my attempt.jpg".
This is my code so far:
figure
Y = [20 40 60 100
0 0 0 0];
h=bar3(Y);
for i = 1:size(Y,2)
zdata = get(h(i),'zdata');
k = 1;
for j = 0:6:(6*size(Y,1)-6)
if Y(k,i)==0
zdata(j+1:j+6,:)= NaN;
end
k = k+1;
end
set(h(i),'zdata',zdata);
end
xlabel('Frequency [kHz]')
ylabel('Current [kA]')
zlabel('Voltage [kV]')
set(gca,'XTick',[1 2 3])
I would be very thankful for all help I can get,
Thank you

Best Answer

A simple way to do this is to understand that the width is y-axis dimension of the bar. To change the width of each bar, just change (bar handle).YData property of that bar. Remember for the first row of bars, the YData varies from 0.5 to 1.5. You can change either one or both endpoints to change the width. One possibility to do this is for your specific script is

% The default range of YData is 0.5 to 1.5, you can change one or both
% extremes to decrease width
h(1).YData(h(1).YData==1.5) = 0.8; % must be > 0.5 and less than 1.5
h(2).YData(h(2).YData==1.5) = 1;
h(3).YData(h(3).YData==1.5) = 1.2;
h(4).YData(h(4).YData==1.5) = 1.5;

just Add these lines at the end of your script. You can configure width by changing the numbers on RHS of these equations.