custom color trendline and appropriate legend
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello! I am having trouble getting my trend line to match my marker colors (which are colors from our template) as the way I tried to enter the custom color was not working for me so for now I have gone back to just r and b so it shows.
Also, I would like to have my legend show either the marker or the trendline, but not have all 4 and I haven't figured out how to do that yet.
Here is what I'm working with so far:
% sample data
PD = [10.7 7.7 8.3 15.7 8.7 11.3 16.0 12.0 15.3 12.3 10.7 15.0 16.7 11.3];
EKDF = [36.5 41.0 35.5 42.5 44.5 37.0 19.5 41.0 32.0 40.0 43.0 37.0 31.5 36.5];
FKDF = [55.0 52.0 43.0 46.0 46.5 49.0 20.5 46.0 36.0 45.0 49.0 41.5 41.5 38.5];
hold on
x1 = EKDF;
y = PD;
sz = 40;
scatter(x1,y,sz,'MarkerEdgeColor',[.5 0 .16],...
'MarkerFaceColor',[.5 0 .16],...
'LineWidth',1.5)
legend('EKDF')
daspect([1 1 1])
coef_fit = polyfit(x1,y,1);
y_fit = polyval(coef_fit,xlim);
plot(xlim,y_fit,'r')
x2 = FKDF;
y = PelvDrop;
scatter(x2,y,sz,'MarkerEdgeColor',[0 .4 .6],...
'MarkerFaceColor',[0 .4 .6],...
'LineWidth',1.5)
legend('FKDF')
coef_fit = polyfit(x2,y,1);
y_fit = polyval(coef_fit,xlim);
plot(xlim,y_fit,'b')
0 commentaires
Réponses (1)
bon sai
le 25 Jan 2018
Assign the scatters to objects in workspace, then make a legend only selected objects
PD = [10.7 7.7 8.3 15.7 8.7 11.3 16.0 12.0 15.3 12.3 10.7 15.0 16.7 11.3];
EKDF = [36.5 41.0 35.5 42.5 44.5 37.0 19.5 41.0 32.0 40.0 43.0 37.0 31.5 36.5];
FKDF = [55.0 52.0 43.0 46.0 46.5 49.0 20.5 46.0 36.0 45.0 49.0 41.5 41.5 38.5];
% hold on
x1 = EKDF;
x2 = FKDF;
y = PD;
sz = 40;
figure;
s1 = scatter(x1,y,sz,'MarkerEdgeColor',[.5 0 .16],...
'MarkerFaceColor',[.5 0 .16],...
'LineWidth',1.5)
legend('EKDF');
daspect([1 1 1])
coef_fit = polyfit(x1,y,1);
y_fit = polyval(coef_fit,xlim);
hold on
plot(xlim,y_fit,'Color',[.5 0 .16])
hold on
s2 = scatter(x2,y,sz,'MarkerEdgeColor',[0 0.4 0.6],...
'MarkerFaceColor',[0 0.4 0.6],...
'LineWidth',1.5);
legend('FKDF')
daspect([1 1 1])
coef_fit = polyfit(x2,y,1);
y_fit = polyval(coef_fit,xlim);
hold on
plot(xlim,y_fit,'Color',[0 0.4 0.6])
legend([s1,s2],{'EKDF','FKDF'})
0 commentaires
Voir également
Catégories
En savoir plus sur Legend dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!