the legend shows different colors than the figure

26 views (last 30 days)
Hello everyone,
I have an errorbar plot, but the legend shows the same color and symbol for all items:
figure (18)
title('Mo21, Vo21final - sily a momenty')
hold on; grid on;
errorbar(Mo21uhel,Mo21final.Fx_original(Mo21idx),Fx,'red-o');
errorbar(Mo21uhel,Mo21final.Fy_original(Mo21idx),Fy,'green-o');
errorbar(Mo21uhel,Mo21final.Mz_original(Mo21idx),Mz,'blue-o');
errorbar(Vo21uhel23,Vo21final23.Fx_original(Vo21idx23),Fx,'red--+');
errorbar(Vo21uhel23,Vo21final23.Fy_original(Vo21idx23),Fy,'green--+');
errorbar(Vo21uhel23,Vo21final23.Mz_original(Vo21idx23),Mz,'blue--+');
errorbar(Vo21uhel45,Vo21final45.Fx_original(Vo21idx45),Fx,'red-+');
errorbar(Vo21uhel45,Vo21final45.Fy_original(Vo21idx45),Fy,'green-+');
errorbar(Vo21uhel45,Vo21final45.Mz_original(Vo21idx45),Mz,'blue-+');
xlabel('\alpha'); ylabel('Fx,Fy,Mz');
legend('Mo21Fx-orig.','Mo21Fy-orig.','Mo21Mz-orig.', ...
'Vo21Fx23-orig.','Vo21Fy23-orig.','Vo21Mz23-orig.', ...
'Vo21Fx45-orig.','Vo21Fy45-orig.','Vo21Mz45-orig.');
The figure:
Please help. Thank you. Petr
  2 Comments
Mathieu NOE
Mathieu NOE on 19 Nov 2025
I don't have your issue with R2025a
tested with dummy data
% dummy data
n = 100;
x = 1:n;
for k=1:9
y{k} = 10*k + 0.1*k*x + 3*sin(x/k)+0.1*randn(size(x));
e{k} = 2*ones(size(x));
end
figure (18)
title('Mo21, Vo21final - sily a momenty')
hold on; grid on;
errorbar(x,y{1},e{1},'red-o');
errorbar(x,y{2},e{2},'green-o');
errorbar(x,y{3},e{3},'blue-o');
errorbar(x,y{4},e{4},'red--+');
errorbar(x,y{5},e{5},'green--+')
errorbar(x,y{6},e{6},'blue--+');
errorbar(x,y{7},e{7},'red-+');
errorbar(x,y{8},e{8},'green-+');
errorbar(x,y{9},e{9},'blue-+');
xlabel('\alpha'); ylabel('Fx,Fy,Mz');
legend('Mo21Fx-orig.','Mo21Fy-orig.','Mo21Mz-orig.', ...
'Vo21Fx23-orig.','Vo21Fy23-orig.','Vo21Mz23-orig.', ...
'Vo21Fx45-orig.','Vo21Fy45-orig.','Vo21Mz45-orig.');
Petr Michalek
Petr Michalek on 25 Nov 2025
I think I found the solution similar to yours. My error values are the same for each errorbar plot, so I multiplied them with the vector of ones.
jednicky = ones(1,73);
figure (1)
title('Mo21 hladky - male modely')
hold on; grid on;
errorbar(uhel_sort,Mo21hladky.Fx_original(index_sort),Fxerr*jednicky,'red-+')
errorbar(uhel_sort,Mo21hladky.Fy_original(index_sort),Fyerr*jednicky,'green-+')
errorbar(uhel_sort,Mo21hladky.Mz_original(index_sort),Mzerr*jednicky,'blue-+')
legend('Mo21-Fx','Mo21-Fy','Mo21-Mz')
xlabel('\alpha'); ylabel('Fx,Fy,Mz')

Sign in to comment.

Answers (0)

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!