Axis ticks alternating between appearing on either side of the plot.

4 visualizaciones (últimos 30 días)
Hi everyone,
I have a question regarding ticks. I want to have the x-ticks where the normal eigenfrequencies are located. However, at times some eigenfrequencies are close to one another. An easy fix for me would be to alternate with the ticks, having some of them show on the left and some on the right. Is there a way to do that?
Thanks in advance and best regards
  1 comentario
DGM
DGM el 27 de Jun. de 2021
I don't know that doing so would accomplish anything that's not still ambiguous. Even if you were to offset the ticks, in cases like the ones near 99, it's still hard to tell which one is which. Color-coding the labels would help, but as far as I know, tick labels can't be individually colored. Using annotations might be an option though.

Iniciar sesión para comentar.

Respuesta aceptada

Scott MacKenzie
Scott MacKenzie el 27 de Jun. de 2021
I think this achieves what you are after (although I concur with @DGM that it may not fully resolve the issue you note):
% test data
y = rand(8,10);
y = [repmat(y(:,1),1,3), y];
n = size(y,1); % number of signals
x = 0:size(y,2)-1;
tiledlayout(2,1);
nexttile;
plot(x, y');
yticks(sort(y(:,1)));
nexttile;
yLeft = y(1:2:n,:); % odd signals with left axis ticks
yRight = y(2:2:n,:); % even signals with right axis ticks
yyaxis left;
plot(x,yLeft', '-');
yticks(sort(yLeft(:,1)));
hold on;
yyaxis right;
plot(x,yRight', '-');
yticks(sort(yRight(:,1)));
  1 comentario
Johannes
Johannes el 27 de Jun. de 2021
Hey Scott I think you nailed it.
It actually resolves my issue fully. It is quite frequent to have two eigenfrequencies very close to one another, as, if we disregard the direction of gravity, we are left with 2 fundamental dimensions for wind and water to come from.
It is much rarer though to have three or more at resonance at very close frequencies. So by simply alternating between the sides, which you showed very well, I ensure that they almost certainly won't be on top of one another.
My goal with the graphs, while unconventional, is to show information without having to waste too many words, and with relatively low effort to the reader, compared to them having to gauge it from a table that might land on a different page than this graph. Hence why even though it might be unconventional, this solution is still good for me.
Thank you very much!

Iniciar sesión para comentar.

Más respuestas (1)

DGM
DGM el 27 de Jun. de 2021
For what it's worth,
nsmp = 20; % test data parameters
nsig = 8;
w = 0.9; % label spreading weight
% make random test data
x = 0:nsmp-1;
y = rand(nsig,nsmp-5) + rand(nsig,1)*5;
y = [repmat(y(:,1),1,5), y];
hg = plot(x,y);
% blindly spread out labels to try to keep them from colliding
% this is a weighted average of given spacing and uniform spacing
[yv idx] = sort(y(:,1),'ascend');
yl = linspace(min(y(:,1)),max(y(:,1)),numel(y(:,1))).'
ya = w*yv + (1-w)*yl;
ya(idx) = ya;
for p = 1:nsig
[xx yy] = datc2figc([-0.5 0],[ya(p) y(p,1)]); % see included file
ha = annotation('textarrow',xx,yy,'string',num2str(y(p,1),4));
ha.Color = get(hg(p),'color'); % make color match
ha.HeadStyle = 'none';
end
set(gca,'ytick',[],'yticklabel',[]) % get rid of regular y ticks and labels
I admit that trying to deal with annotations is a great way to lose your hair. The included file (or something which accomplishes the same) is almost universally necessary in order to use annotations for any typical purpose.

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by