yyaxis plot is not working properly

조회 수: 28 (최근 30일)
Amir Hosein Shokouhy
Amir Hosein Shokouhy 2021년 7월 21일
댓글: Amir Hosein Shokouhy 2021년 7월 22일
Hi,
I have this double axis plot. the right side plot consists of 14 plots itself and I want it to be shown with different colors (like the second plot below), but I get them all with the same weird brown color.
Left side plot:
right side plot:
combined:
and here's the code I'm using:
figure(9)
yyaxis left
for i=1:size(w_SSI_r,2)
y_mode{i} = ones(size(w_SSI_r{i},1),1)*(i+n_o_min-1);
xlim([0 35])%%%%%%%%%%
ylim([n_o_min n_o_max])
scatter(w_SSI_r{i}/(2*pi),y_mode{i},'MarkerFaceColor','r','MarkerEdgeColor','k')
hold on
grid on
y_mode_st0{i} = ones(size(w_SSI_r_st{i},1),1)*(i+n_o_min-1);
scatter(w_SSI_r_st{i}/(2*pi),y_mode_st0{i},'MarkerFaceColor','g','MarkerEdgeColor','k')
hold on
grid on
end
%legend('Unstable Poles in Frequency','Stable Poles in Frequency')
ylabel('Model Order');
xlabel('Frequency (Hz)');
%title('Stabilization Diagram');
yyaxis right
for i=1:NDOF
plot(f_FDD,pow2db(SV_FDD{i}),'DisplayName',['SV ',num2str(i)]);
xlabel('Frequency (Hz)');
ylabel('Singular Value (Power Spectral Density)(dB)');
title('Singular Values of the SD Matrix')
%xlim([0 round(max(Peaks_FDD_x))+1])
%legend
hold on
grid on
end
ax = gca;
ax.YAxis(1).Color = 'k';
ax.YAxis(2).Color = 'k';

채택된 답변

Cris LaPierre
Cris LaPierre 2021년 7월 21일
See the Algorithms section of the yyaxis documentation page for an explanation of what is happening. Basically, yyaxis left will plot everything using the first color in the color order. You don't see that because you specify the color for those objects.
yyaxis right, then, uses the second color in the color order for all objects plotted on it.
yyaxis left
xlim([0 35])
ylim([15 60])
scatter(randi([0 35],[1 50]),randi([15 60],[1 50]))
hold on
scatter(randi([0 35],[1 50]),randi([15 60],[1 50]))
hold off
grid on
ylabel('Model Order');
xlabel('Frequency (Hz)');
yyaxis right
plot(randi([-90 -60],[35,4]));
ylim([-90 -10])
ylabel('Singular Value (Power Spectral Density)(dB)');
title('Singular Values of the SD Matrix')
The fix is to reset the colororder to default.
figure
yyaxis left
xlim([0 35])
ylim([15 60])
scatter(randi([0 35],[1 100]),randi([15 60],[1 100]),'MarkerFaceColor','r','MarkerEdgeColor','k')
hold on
scatter(randi([0 35],[1 100]),randi([15 60],[1 100]),'MarkerFaceColor','g','MarkerEdgeColor','k')
hold off
grid on
ylabel('Model Order');
xlabel('Frequency (Hz)');
yyaxis right
% reset the colorder
colororder('default')
plot(randi([-90 -60],[35,4]));
ylim([-90 -10])
ylabel('Singular Value (Power Spectral Density)(dB)');
title('Singular Values of the SD Matrix')
The fix is to reset the colororder before plotting into yyaxis right.
  댓글 수: 3
Cris LaPierre
Cris LaPierre 2021년 7월 21일
Set the linestyle in your plot command.
plot(randi([-90 -60],[35,4]),'LineStyle',"-");
If your linestyle is changing, that means MATLAB has already gone through all colors in the color order (there are 7 by default). Overriding this means you will have different data series that will look exactly the same (same color, marker and linestyle).
Amir Hosein Shokouhy
Amir Hosein Shokouhy 2021년 7월 22일
Perfect, thank you very much!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by