Is it possible to subplot graphs with 7 y-axis in a figure and how ?
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
el 20 de Mzo. de 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?
Respuesta aceptada
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
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)
Más respuestas (0)
Ver también
Categorías
Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!