how to plot more than 2 data sets onto one figure with two y-axes and one x-axis, with multiple datasets plotted with respect to the second y-axes and multiple datasets with respect to the first y-axis

9 views (last 30 days)
Hello,
I'm trying to plot multiple lines (total of 12 data sets) onto one Figure with two y-axes and one x-axis. So far, I have multiple lines onto one Figure, but with one y-axis and one x-axis as shown below. I would like the group of lines at the bottom of the plot (total of 6 data sets) to be plotted (in scale with) or with respect to the second y-axis (not shown in image).
The farthest I've gotten was using the plotyy function, and having one data set plotted in scale with (or with respect to) the second y-axis, but the rest of the lines (11 data sets) plotted in scale with (or with respect to) the first y-axis...does that make sense? Any help would be greatly appreciated.
I initially imported a .txt data file and filtered the data to op_data and non_op_data if you're wondering. I'm using MATLAB R2015a btw. I hope this makes enough sense.
Thanks
RPM = TestCase1.data(:,2);
[row] = find(RPM > 150);
[row_non_op] = find(RPM <= 150); %non_op_row
op_data = TestCase1.data(row,:); %op_data
non_op_data = TestCase1.data(row_non_op,:); %non_op_data
d = TestCase1.textdata(2:end,1); %textdata of timestamp
date = datetime(d,'InputFormat','M/d/y h:mm:ss a'); %Converting textdata into a datetime array
op_date = date(row,1); %op_date
non_op_date = date(row_non_op,1); %non_op_date
non_op_data(:,4:9) = NaN;
if num_cyl == 6
PP_CYL_op = op_data(:,4:9);
SDoPP_CYL_op = op_data(:,10:15);
figure (); hold on
for i = 1:num_cyl
plot(op_date,PP_CYL_op(:,i))
end
hold on
for i = 1:num_cyl
plot(op_date,SDoPP_CYL_op(:,i))
end
end

Accepted Answer

Star Strider
Star Strider on 21 Jul 2015
In the plotyy documentation, see: Use Right y-Axis for Two Data Sets. That may be what you want.
  5 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!