yyaxis plot is not working properly
25 次查看(过去 30 天)
显示 更早的评论
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/691695/image.png)
right side plot:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/691699/image.png)
combined:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/691703/image.png)
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';
0 个评论
采纳的回答
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
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).
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!