
Plot line type not displaying as desired .
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Eric Geraldo De-Lima
le 1 Jan 2022
Modifié(e) : Eric Geraldo De-Lima
le 3 Jan 2022
I desire to create a plot with lines running through circular markers. For some reason, this does not plot as desired, but is registered correctly in the legend. I made an attempt with 'dummy variables ', whose limits were based on the limits of the actual variables I am working with, and that worked perfectly. Why does the plot not display as desired? A solution for this would be most appreciated. Attached is the script used.
% actual variables to be plotted
kf_max_SW_A = [ 0.0013 0.0049 0.0010 0.0011 0.0005 0.0007 ;
0.9845 1.0853 0.9962 0.9738 0.9454 0.9178 ] ;
Id_A = [ 51.6400 29.2000 61.3600 63.5000 77.2100 76.1200 ] ;
% dummy var xxx & yyy
xxx = linspace(20, 80, 5) ;
yyy = linspace(0*1e-3, 5*1e-3, 5) ;
% Plotting variables
figure(1)
clf
% the required plot
plot( Id_A(1,1), kf_max_SW_A(1,1) , '-ok', 'LineWidth', 0.5, 'MarkerSize',5 , 'DisplayName', 'Max')
hold on ;
for i = 2 : length( kf_max_SW_A)
plot( Id_A(1,i), kf_max_SW_A(1,i) , '-ok', 'LineWidth', 0.5, 'MarkerSize',5 , 'HandleVisibility','off')
hold on ;
end
% the dummy plot
plot(xxx, yyy,'-or' ) ; hold off;
title(' Why do the variables for legend item Max not plot as desired ?')
xlabel('x-axis')
ylabel('y-axis')
legend('show');
legend('location','best') ;
0 commentaires
Réponse acceptée
Simon Chan
le 1 Jan 2022
Try the following to sort the x-axis in correct order:
figure(1)
clf
[sort_Id_A,idx] = sort(Id_A);
sort_kf_max_SW_A = kf_max_SW_A(1,idx);
plot(sort_Id_A, sort_kf_max_SW_A , '-ok', 'LineWidth', 0.5, 'MarkerSize',5 , 'DisplayName', 'Max')
title('Is this your desired plot?')
xlabel('x-axis')
ylabel('y-axis')
legend('show');
legend('location','best') ;

1 commentaire
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Annotations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!