0
votes

I have three vectors m1, v1, and v2 all of equal length. Vector m1 has values in range [1000,10000] whereas v1 and v2 have values in range [1,2]. I want to plot a bar graph with all three vectors, but I want vectors v1 and v2 to use a smaller y-axis scale than m1. I have found multiple sources (e.g. Matlab bar plot grouped but in different y scales) that recommend the following function for doing this with two vectors (m1, and v1)

plotyy(xrange-offset, m1, xrange+offset, v1, 'bar','bar')

However, I have not been able to figure out how to add v2 to this plot with the same scale as v1. Is there any way to do this in MATLAB?

1

1 Answers

1
votes

Each X,Y pair supplied as inputs to plotyy is treated as a separate input to the plotting function. That being said, it is definitely possible to generate multiple plots for the same y scale.

So X1 and Y1 (the first two inputs to plotyy) are the treated the same as passing two inputs to bar and accoriding to the documentation

BAR(X,Y) draws the columns of the M-by-N matrix Y as M groups of N vertical bars. The vector X must not have duplicate values

The same format is also accepted for X2 and Y2 inputs to plotyy. So if you want to group v1 and v2 onto the same vertical scale you'll want to do something like the following.

plotyy(xrange - offset, m1, xrange + offset, [v1(:), v2(:)], 'bar', 'bar');