Borrar filtros
Borrar filtros

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

15 visualizaciones (últimos 30 días)
LIU
LIU el 20 de Mzo. de 2022
Editada: DGM el 21 de Mzo. de 2022
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 comentarios
Steven Lord
Steven Lord el 20 de Mzo. de 2022
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 el 21 de Mzo. de 2022
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.

Iniciar sesión para comentar.

Respuesta aceptada

DGM
DGM el 20 de Mzo. de 2022
Editada: DGM el 20 de Mzo. de 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 comentarios
LIU
LIU el 21 de Mzo. de 2022
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 el 21 de Mzo. de 2022
Editada: DGM el 21 de Mzo. de 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)

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by