Is it possible to subplot graphs with 7 y-axis in a figure and how ?

6 次查看(过去 30 天)
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 个评论
Steven Lord
Steven Lord 2022-3-20
Showing data using 2 Y axes together can be confusing and/or misleading if not handled carefully.
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?
LIU
LIU 2022-3-21
Thank you for your kind comment, Steven Lord. Maybe I could say sometimes one graph with several lines is needed in convenience of space saving, especially when there are more than one graph of such kind.

请先登录,再进行评论。

采纳的回答

DGM
DGM 2022-3-20
编辑:DGM 2022-3-20
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 个评论
LIU
LIU 2022-3-21
Hi DGM, It is quite useful for me to use this tool when plotting 7 lines into one graph with 7 y-axis displayed. I am encoutered with another problem, each y-axis is too far away from each other just as what shows on the right side of the figure attached, but I need a much more compact one just as what shows on the left side. I don't know how to set or modify the options of the addaxis function to get a compact y-axis layout, could anyone kindly help me ? Many thanks.
Best regards,
LIU
DGM
DGM 2022-3-21
编辑:DGM 2022-3-21
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)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by