Is it possible to subplot graphs with 7 y-axis in a figure and how ?
7 views (last 30 days)
Show older comments
Hi all,
I have got great help in this forum eight years ago, I am much appreciated for that.This time I am confused with another similar problem again. I need to subplot graphs with 7 y-axis in a figure now, i.e., 7 lines in a figure. Is it possible to amend the plotyyyy code to achieve this? If possible, can you give me some hint of how to do it ? Many thanks in advance.
Best regards,
Liu
4 Comments
Steven Lord
on 20 Mar 2022
I would be very worried that putting seven Y axes together would make the graph completely uninterpretable. A picture may be worth a thousand words, but how many of those words uttered by people viewing your picture would be profane?
Accepted Answer
DGM
on 20 Mar 2022
Edited: DGM
on 20 Mar 2022
I've used addaxis() before:
... but it hasn't been maintained since 2016, so some things are broken and will need to be edited before it will work. Namely, aa_splot.m will need instances of the property name 'colorord' replaced with 'colororder'. I don't remember if there were other things I edited.
This is an example of using addaxis(), showing that it does work if you work around its limitations.
3 Comments
DGM
on 21 Mar 2022
Edited: DGM
on 21 Mar 2022
There may be ways to do this within the manangement tools that come with addaxis(), but I've come to avoid those. I just prefer to set all the common properties using basic tools instead of dealing with the base and added axes with different tools.
In this case, I just set the ruler positions manually. The ylabels are children and their position could similarly be adjusted, but that's just another layer of complexity. Trying to deal with the exponents might be another story. I think you can move those via the hax(k).YRuler.SecondaryLabel.Position property, but there may be complications. You should also be able to rotate them if that helps.
N = 10;
time = linspace(1,24,N);
D = rand(7,N);
ylimits = [0 2];
plot(time,D(1,:))
ylim(ylimits)
for k = 2:size(D,1)
addaxis(time,D(k,:),ylimits);
end
ylabels = {'A','B','C','D','E','F','G'};
xlabel('Time (hours)');
hax = getaddaxisdata(gca,'axisdata');
hax = [hax{:}];
hax = [gca hax(1,:)];
x0 = 0.1; % spacing between outermost rulers and figure edge
xgap = 0.06; % spacing between rulers
fontsize = 8; % base font size for all rulers/labels
% get info about ruler locations
nlr = nnz(strcmp({hax.YAxisLocation},'left'));
nrr = numel(hax) - nlr;
% calculate x-offsets for rulers, reorder to match axes order
xposl = x0+(0:nlr-1)*xgap;
xposr = 1-(x0+(nrr-1:-1:0)*xgap);
xpos = zeros(1,numel(hax));
xpos(1:2:nlr*2) = fliplr(xposl);
xpos(2:2:nrr*2) = xposr;
% width of primary axes
wax = 1 - ((nlr-1)+(nrr-1))*xgap - 2*x0;
% apply properties
for k = 1:numel(hax)
hax(k).Position(1) = xpos(k);
hax(k).YLabel.String = ylabels{k};
hax(k).FontSize = fontsize;
end
hax(1).Position(3) = wax;
legend(ylabels)
More Answers (0)
See Also
Categories
Find more on 2-D and 3-D Plots 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!