Effacer les filtres
Effacer les filtres

Color Coding Data Points Using Scatter

20 vues (au cours des 30 derniers jours)
nicole
nicole le 5 Mar 2023
Modifié(e) : Voss le 5 Mar 2023
Hi all,
I hope everyone is doing well!
I have a picture of my code, and am wanting to color code my thresholds according to colors of my choosing instead of the default RGB colors, as the RGB plot does not show the pattern of the data well.
I can not figure out how to make the points themselves the colors that I want, only how to divide them according to RGB colors. Does anyone have any advice on how to do this?

Réponses (1)

Voss
Voss le 5 Mar 2023
Modifié(e) : Voss le 5 Mar 2023
% random data
T = [10 25 40 50 75];
alldataoxides = struct( ...
'pHs',3+9*rand(1,100), ...
'kds',80*rand(1,100), ...
'Temperature',T(randi(numel(T),1,100)));
% define your pH thresholds (i.e., bin edges)
pHs = [7.0, 9.1];
% define your colors (one for each bin -> one more color than you have thresholds)
colors = [ ...
0.4 0 1; ...
0 0.6 0.4; ...
1 0.6 0; ...
];
% put -Inf and Inf on the ends to include the lowest and highest bins
bin_edges = [-Inf, pHs, Inf];
% bin_idx is which bin each pH value is in
bin_idx = discretize(alldataoxides.pHs,bin_edges);
% color matrix -> the color of each data point
colorIDb = colors(bin_idx,:)
colorIDb = 100×3
0.4000 0 1.0000 1.0000 0.6000 0 0.4000 0 1.0000 0.4000 0 1.0000 0.4000 0 1.0000 0.4000 0 1.0000 0.4000 0 1.0000 1.0000 0.6000 0 1.0000 0.6000 0 0 0.6000 0.4000
% scatter plot
sz = 50;
figure(7); hold on; box on;
scatter(alldataoxides.Temperature, log10(alldataoxides.kds), sz, colorIDb, 'filled')

Catégories

En savoir plus sur Scatter Plots 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!

Translated by