Ask an expert. Trust the answer.

Your academic and career questions answered by verified experts

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. 


Why Matlabhelpers ?

Our Matlab assignment helpers for online MATLAB assignment help service take utmost care of your assignments by keeping the codes simple yet of high-quality. We offer the most reliable MATLAB solutions to students pursuing their Computer Science course from the Monash University, the University of Sydney, the University of New South Wales, the University of Melbourne; to name a few. Approach us today for best Matlab solutions online!

whatsApp order on matlabhelpers.com

telegram order on matlabsolutions.com