MATLAB: How to combine stacked bar chart and line chart

2-axes graphline chartplottingstacked bar

I'm finding a way to combine a stacked bar chart and line chart look like this:
I have tried to use 2-axes graph in (https://www.mathworks.com/help/matlab/creating_plots/overlay-line-plot-on-bar-graph-using-different-y-axes-1.html)
and used the following code:
yyaxis left
b = bar(step,array,'stacked');
yyaxis right
p = plot(step,entropy);
But it seems not to work properly and the result is:
PS: I have 4 components in 1 bar. Sometimes, there's only 1 component presents inside the bar. The line graph works as expected though. Only the stacked bar has problems.

Best Answer

Seems to work fine here...
figure
hB=bar(step,array,'stacked');
ylim([0 16])
xlim(xlim+[1 -1]*500)
yyaxis right
hL=plot(step,randi(15,1,6),'*-r');
yielded
The figure you show must have had 10-gazillion x values to have made such a blob.