How to apply individual color to each bar on a bar chart plot
The code is working perfect, but all the bars are showing blue color by default, I want each bar to have a diffrent color. The code is divided into two files: The function part and the normal code
The Function file
function plotResults(Cleveland_accuracy, Cleveland_sensitivity, Cleveland_specificity, Cleveland_precision, Cleveland_fScore, Cleveland_mcc, Public_Health_Dataset_accuracy, Public_Health_Dataset_sensitivity, Public_Health_Dataset_specificity, Public_Health_Dataset_precision, Public_Health_Dataset_fScore, Public_Health_Dataset_mcc, Jindong_accuracy, Jindong_sensitivity, Jindong_specificity)
figure
cats = categorical({‘Cleveland Dataset’,’Public Health Dataset’});
cats = reordercats(cats, {‘Cleveland Dataset’,’Public Health Dataset’});
results = [Cleveland_accuracy Cleveland_sensitivity Cleveland_specificity Cleveland_precision Cleveland_fScore Cleveland_mcc;…
Public_Health_Dataset_accuracy Public_Health_Dataset_sensitivity Public_Health_Dataset_specificity Public_Health_Dataset_precision Public_Health_Dataset_fScore Public_Health_Dataset_mcc];
bar(cats, results);
ylabel(‘Metric Value (%)’);
legend(‘Accuracy’, ‘Sensitivity’, ‘Specificity’, ‘Precision’, …
‘F1-Score’, ‘Matthews correlation coefficient’, ‘Location’, ‘northoutside’);
% Accuracy comparison for the three model
figure
cats = categorical({‘Cleveland Model’, ‘Jindong et al Model’,’Public Health Model’});
cats = reordercats(cats, {‘Cleveland Model’, ‘Jindong et al Model’,’Public Health Model’});
results = [Cleveland_accuracy ;…
Jindong_accuracy;…
Public_Health_Dataset_accuracy];
bar(cats, results);
ylabel(‘Accuracy Values (%)’);
legend(‘Accuracy’, …
‘Location’, ‘northoutside’);
% Sensitivity comparison for the three model
figure
cats = categorical({‘Cleveland Model’, ‘Jindong et al Model’,’Public Health Model’});
cats = reordercats(cats, {‘Cleveland Model’, ‘Jindong et al Model’,’Public Health Model’});
results = [Cleveland_sensitivity ;…
Jindong_sensitivity;…
Public_Health_Dataset_sensitivity];
bar(cats, results);
ylabel(‘Sensitivity Values (%)’);
legend(‘Sensitivity’, ‘Location’, ‘northoutside’);
% SPecificity comparison for the three model
figure
cats = categorical({‘Cleveland Model’, ‘Jindong et al Model’,’Public Health Model’});
cats = reordercats(cats, {‘Cleveland Model’, ‘Jindong et al Model’,’Public Health Model’});
results = [Cleveland_specificity ;…
Jindong_specificity;…
Public_Health_Dataset_specificity];
bar(cats, results);
ylabel(‘SPecificity Values (%)’);
legend(‘SPecificity’, ‘Location’, ‘northoutside’);
end
%To call the fuction we have the following codenin a separate file
% Metric values for the main model
Cleveland_accuracy = 99;
Cleveland_sensitivity = 97;
Cleveland_specificity = 100;
Cleveland_precision = 100;
Cleveland_fScore = 98;
Cleveland_mcc = 79;
% Metrics values for Jindong Feng et al model
Jindong_accuracy = 91.25;
Jindong_sensitivity = 91.54;
Jindong_specificity = 90.32;
% Metric values for the combined dataset model
Public_Health_Dataset_accuracy = 87;
Public_Health_Dataset_sensitivity = 77;
Public_Health_Dataset_specificity = 98;
Public_Health_Dataset_precision = 98;
Public_Health_Dataset_fScore = 86;
Public_Health_Dataset_mcc = 75;
% Call the plotResults function with metric values
plotResults(Cleveland_accuracy, Cleveland_sensitivity, Cleveland_specificity, …
Cleveland_precision, Cleveland_fScore, Cleveland_mcc, Public_Health_Dataset_accuracy, Public_Health_Dataset_sensitivity, Public_Health_Dataset_specificity, Public_Health_Dataset_precision, Public_Health_Dataset_fScore, Public_Health_Dataset_mcc, Jindong_accuracy, Jindong_sensitivity, Jindong_specificity);The code is working perfect, but all the bars are showing blue color by default, I want each bar to have a diffrent color. The code is divided into two files: The function part and the normal code
The Function file
function plotResults(Cleveland_accuracy, Cleveland_sensitivity, Cleveland_specificity, Cleveland_precision, Cleveland_fScore, Cleveland_mcc, Public_Health_Dataset_accuracy, Public_Health_Dataset_sensitivity, Public_Health_Dataset_specificity, Public_Health_Dataset_precision, Public_Health_Dataset_fScore, Public_Health_Dataset_mcc, Jindong_accuracy, Jindong_sensitivity, Jindong_specificity)
figure
cats = categorical({‘Cleveland Dataset’,’Public Health Dataset’});
cats = reordercats(cats, {‘Cleveland Dataset’,’Public Health Dataset’});
results = [Cleveland_accuracy Cleveland_sensitivity Cleveland_specificity Cleveland_precision Cleveland_fScore Cleveland_mcc;…
Public_Health_Dataset_accuracy Public_Health_Dataset_sensitivity Public_Health_Dataset_specificity Public_Health_Dataset_precision Public_Health_Dataset_fScore Public_Health_Dataset_mcc];
bar(cats, results);
ylabel(‘Metric Value (%)’);
legend(‘Accuracy’, ‘Sensitivity’, ‘Specificity’, ‘Precision’, …
‘F1-Score’, ‘Matthews correlation coefficient’, ‘Location’, ‘northoutside’);
% Accuracy comparison for the three model
figure
cats = categorical({‘Cleveland Model’, ‘Jindong et al Model’,’Public Health Model’});
cats = reordercats(cats, {‘Cleveland Model’, ‘Jindong et al Model’,’Public Health Model’});
results = [Cleveland_accuracy ;…
Jindong_accuracy;…
Public_Health_Dataset_accuracy];
bar(cats, results);
ylabel(‘Accuracy Values (%)’);
legend(‘Accuracy’, …
‘Location’, ‘northoutside’);
% Sensitivity comparison for the three model
figure
cats = categorical({‘Cleveland Model’, ‘Jindong et al Model’,’Public Health Model’});
cats = reordercats(cats, {‘Cleveland Model’, ‘Jindong et al Model’,’Public Health Model’});
results = [Cleveland_sensitivity ;…
Jindong_sensitivity;…
Public_Health_Dataset_sensitivity];
bar(cats, results);
ylabel(‘Sensitivity Values (%)’);
legend(‘Sensitivity’, ‘Location’, ‘northoutside’);
% SPecificity comparison for the three model
figure
cats = categorical({‘Cleveland Model’, ‘Jindong et al Model’,’Public Health Model’});
cats = reordercats(cats, {‘Cleveland Model’, ‘Jindong et al Model’,’Public Health Model’});
results = [Cleveland_specificity ;…
Jindong_specificity;…
Public_Health_Dataset_specificity];
bar(cats, results);
ylabel(‘SPecificity Values (%)’);
legend(‘SPecificity’, ‘Location’, ‘northoutside’);
end
%To call the fuction we have the following codenin a separate file
% Metric values for the main model
Cleveland_accuracy = 99;
Cleveland_sensitivity = 97;
Cleveland_specificity = 100;
Cleveland_precision = 100;
Cleveland_fScore = 98;
Cleveland_mcc = 79;
% Metrics values for Jindong Feng et al model
Jindong_accuracy = 91.25;
Jindong_sensitivity = 91.54;
Jindong_specificity = 90.32;
% Metric values for the combined dataset model
Public_Health_Dataset_accuracy = 87;
Public_Health_Dataset_sensitivity = 77;
Public_Health_Dataset_specificity = 98;
Public_Health_Dataset_precision = 98;
Public_Health_Dataset_fScore = 86;
Public_Health_Dataset_mcc = 75;
% Call the plotResults function with metric values
plotResults(Cleveland_accuracy, Cleveland_sensitivity, Cleveland_specificity, …
Cleveland_precision, Cleveland_fScore, Cleveland_mcc, Public_Health_Dataset_accuracy, Public_Health_Dataset_sensitivity, Public_Health_Dataset_specificity, Public_Health_Dataset_precision, Public_Health_Dataset_fScore, Public_Health_Dataset_mcc, Jindong_accuracy, Jindong_sensitivity, Jindong_specificity); The code is working perfect, but all the bars are showing blue color by default, I want each bar to have a diffrent color. The code is divided into two files: The function part and the normal code
The Function file
function plotResults(Cleveland_accuracy, Cleveland_sensitivity, Cleveland_specificity, Cleveland_precision, Cleveland_fScore, Cleveland_mcc, Public_Health_Dataset_accuracy, Public_Health_Dataset_sensitivity, Public_Health_Dataset_specificity, Public_Health_Dataset_precision, Public_Health_Dataset_fScore, Public_Health_Dataset_mcc, Jindong_accuracy, Jindong_sensitivity, Jindong_specificity)
figure
cats = categorical({‘Cleveland Dataset’,’Public Health Dataset’});
cats = reordercats(cats, {‘Cleveland Dataset’,’Public Health Dataset’});
results = [Cleveland_accuracy Cleveland_sensitivity Cleveland_specificity Cleveland_precision Cleveland_fScore Cleveland_mcc;…
Public_Health_Dataset_accuracy Public_Health_Dataset_sensitivity Public_Health_Dataset_specificity Public_Health_Dataset_precision Public_Health_Dataset_fScore Public_Health_Dataset_mcc];
bar(cats, results);
ylabel(‘Metric Value (%)’);
legend(‘Accuracy’, ‘Sensitivity’, ‘Specificity’, ‘Precision’, …
‘F1-Score’, ‘Matthews correlation coefficient’, ‘Location’, ‘northoutside’);
% Accuracy comparison for the three model
figure
cats = categorical({‘Cleveland Model’, ‘Jindong et al Model’,’Public Health Model’});
cats = reordercats(cats, {‘Cleveland Model’, ‘Jindong et al Model’,’Public Health Model’});
results = [Cleveland_accuracy ;…
Jindong_accuracy;…
Public_Health_Dataset_accuracy];
bar(cats, results);
ylabel(‘Accuracy Values (%)’);
legend(‘Accuracy’, …
‘Location’, ‘northoutside’);
% Sensitivity comparison for the three model
figure
cats = categorical({‘Cleveland Model’, ‘Jindong et al Model’,’Public Health Model’});
cats = reordercats(cats, {‘Cleveland Model’, ‘Jindong et al Model’,’Public Health Model’});
results = [Cleveland_sensitivity ;…
Jindong_sensitivity;…
Public_Health_Dataset_sensitivity];
bar(cats, results);
ylabel(‘Sensitivity Values (%)’);
legend(‘Sensitivity’, ‘Location’, ‘northoutside’);
% SPecificity comparison for the three model
figure
cats = categorical({‘Cleveland Model’, ‘Jindong et al Model’,’Public Health Model’});
cats = reordercats(cats, {‘Cleveland Model’, ‘Jindong et al Model’,’Public Health Model’});
results = [Cleveland_specificity ;…
Jindong_specificity;…
Public_Health_Dataset_specificity];
bar(cats, results);
ylabel(‘SPecificity Values (%)’);
legend(‘SPecificity’, ‘Location’, ‘northoutside’);
end
%To call the fuction we have the following codenin a separate file
% Metric values for the main model
Cleveland_accuracy = 99;
Cleveland_sensitivity = 97;
Cleveland_specificity = 100;
Cleveland_precision = 100;
Cleveland_fScore = 98;
Cleveland_mcc = 79;
% Metrics values for Jindong Feng et al model
Jindong_accuracy = 91.25;
Jindong_sensitivity = 91.54;
Jindong_specificity = 90.32;
% Metric values for the combined dataset model
Public_Health_Dataset_accuracy = 87;
Public_Health_Dataset_sensitivity = 77;
Public_Health_Dataset_specificity = 98;
Public_Health_Dataset_precision = 98;
Public_Health_Dataset_fScore = 86;
Public_Health_Dataset_mcc = 75;
% Call the plotResults function with metric values
plotResults(Cleveland_accuracy, Cleveland_sensitivity, Cleveland_specificity, …
Cleveland_precision, Cleveland_fScore, Cleveland_mcc, Public_Health_Dataset_accuracy, Public_Health_Dataset_sensitivity, Public_Health_Dataset_specificity, Public_Health_Dataset_precision, Public_Health_Dataset_fScore, Public_Health_Dataset_mcc, Jindong_accuracy, Jindong_sensitivity, Jindong_specificity); barplot, bar MATLAB Answers — New Questions