Multiple Y-axis labels in a MATLAB figure
Date: 2022-12-13 11:23:10
OK for example the numeric value of one of my data is large and the numeric value of one of my data is small.
A = [130000 310000 200000 400000]'; B = [16 32 5 10]';
I am doing the following.
figure; bar(1:4,[A B],0.5,'stack');
Since the value of A
is lot high than B
, I want a secondary y
-axis. Otherwise the values of B
cannot be seen on the stacked bar chart.
Answer:
You can use plotyy
to plot two bar charts on different y-axes in the same figure.
x = [1,2,3]; y1 = [1000,2000,3000]; y2 = [0.5,0.3,0.1]; [AX,H1,H2] = plotyy(x, y1, x, y2, 'bar', 'bar'); set(H1, 'FaceColor', [1 0 0], 'BarWidth', 1)
This isn't a stacked bar chart like you had before (one set of data vertically on top of the other) but it doesn't make sense include data on different scales in a stacked bar chart.