Filter löschen
Filter löschen

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

5 Ansichten (letzte 30 Tage)
Jacob Allen
Jacob Allen am 2 Apr. 2022
Beantwortet: Voss am 2 Apr. 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

Akzeptierte Antwort

Voss
Voss am 2 Apr. 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

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by