yyaxis plot is not working properly

24 ビュー (過去 30 日間)
Amir Hosein Shokouhy
Amir Hosein Shokouhy 2021 年 7 月 21 日
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 Center および File ExchangeAnnotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by