Effacer les filtres
Effacer les filtres

How do I change the colors of my data points in a scatter plot?

5 vues (au cours des 30 derniers jours)
Jacob Allen
Jacob Allen le 2 Avr 2022
Réponse apportée : Voss le 2 Avr 2022
Attached below is the code I am working with and the associated excel sheet. I need to be able to change the data point's color from the default of blue to red. I am relativly new to MatLab so explanations of code when answering would be greatly appricated but not necessary.
depth = xlsread('942 Raw data.xlsx', 'Sheet1', 'I:I');
bulkdensity = xlsread('942 Raw data.xlsx', 'Sheet1', 'L:L');
graindensity = xlsread('942 Raw data.xlsx', 'Sheet1', 'N:N');
porosity = xlsread('942 Raw data.xlsx', 'Sheet1', 'O:O');
voidratio = xlsread('942 Raw data.xlsx', 'Sheet1', 'P:P');
data = [depth bulkdensity graindensity porosity voidratio];
%%
data = sortrows(data,1);
depth = data(:,1);
bulkdensity = data(:,2);
graindensity = data(:,3);
porosity = data(:,4);
voidratio = data(:,5);
%%
depth = [0;depth];
N = diff(depth);
a = (bulkdensity - 1.024)*9.81.*N/1000;
Ov = cumsum(a);
%%
figure(1)
plot(porosity,depth(2:end),'.');
axis ij
xlabel ('Porosity(%)');
ylabel ('Depth(m)');
hold on
%%
figure(2)
semilogx(Ov,voidratio,'.');
xlabel('Sv');
ylabel('voidratio');
hold on

Réponse acceptée

Voss
Voss le 2 Avr 2022
Here is a link to the documentation explaining what the options and syntax are for changing line properties (including color) in plot (semilogx has the same options and syntax for this).
Below is how you might make those two plots red:
depth = xlsread('942 Raw data.xlsx', 'Sheet1', 'I:I');
bulkdensity = xlsread('942 Raw data.xlsx', 'Sheet1', 'L:L');
graindensity = xlsread('942 Raw data.xlsx', 'Sheet1', 'N:N');
porosity = xlsread('942 Raw data.xlsx', 'Sheet1', 'O:O');
voidratio = xlsread('942 Raw data.xlsx', 'Sheet1', 'P:P');
data = [depth bulkdensity graindensity porosity voidratio];
%%
data = sortrows(data,1);
depth = data(:,1);
bulkdensity = data(:,2);
graindensity = data(:,3);
porosity = data(:,4);
voidratio = data(:,5);
%%
depth = [0;depth];
N = diff(depth);
a = (bulkdensity - 1.024)*9.81.*N/1000;
Ov = cumsum(a);
%%
figure(1)
plot(porosity,depth(2:end),'r.');
axis ij
xlabel ('Porosity(%)');
ylabel ('Depth(m)');
hold on
%%
figure(2)
semilogx(Ov,voidratio,'r.');
xlabel('Sv');
ylabel('voidratio');
hold on

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by