0
votes

Hi I have the 3D matrix daily_renewables_excess which I am trying to plot a 3D bar graph for the x y and z dimensions in axis. The size(daily_renewables_excess) is 11,7,10. So I am trying to get a 3D bar chart with 11 x intervals of x, 7 of y and 10 of z.

However when i try

figure;
bar3(daily_renewables_excess(:,:,:))

I get an error saying "Error using bar3 (line 39) Inputs must be 2-D."

From my understanding of the documentation, the bar3 function will plot a 3D bar as above. Do I need to rearrange the matrices somehow?

thank you

1

1 Answers

1
votes

Since you have a 3D matrix (volume) you cannot simultaneously show 3 intervals (3 axis) + a scale value for the bars (4th variable). This would amount to plotting a 4D diagram (e.g. using color to color-code the 4-th dimension, bar size to size-code it, or even vertical stacking).

For example, the following volume D is of size [11x10x7] and you can get 7 bar3 plots by indexing in the 3rd (z) dimension

% random 3D input
D = randi(10, [11, 10, 7]);
[m,n,l] = size(D);
% plot bar for first z-
figure; bar3(D(:,:,1));

enter image description here

What you can do instead is reshape in either x- or y- dimesions, sort (in order to keep the notion of ordered intervals (in x- or y- respectively) and plot with bar3 the resulting matrices.

% reshape to x
Dx = reshape(D, m*l, n);
Dx = sort(Dx, 1, 'descend'); 
figure; bar3(Dx)

enter image description here

% reshape to y
Dy = reshape(D, m, n*l);
Dy = sort(Dy, 2, 'descend'); 
figure; bar3(Dy)

enter image description here