フィルターのクリア

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

5 ビュー (過去 30 日間)
Jacob Allen
Jacob Allen 2022 年 4 月 2 日
回答済み: Voss 2022 年 4 月 2 日
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

採用された回答

Voss
Voss 2022 年 4 月 2 日
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

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by