Why am I not getting a colorcoded plot?

1 ビュー (過去 30 日間)
Muazma Ali
Muazma Ali 2022 年 7 月 31 日
回答済み: Image Analyst 2022 年 7 月 31 日
I dont understand why I am not getting a colorcoded plot, it shd be colorcoded with the z-values but it isnt

回答 (2 件)

Dyuman Joshi
Dyuman Joshi 2022 年 7 月 31 日
編集済み: Dyuman Joshi 2022 年 7 月 31 日
You are using plot3 to make your graph, in that case, you can not change the color of the points in line individually.
Use scatter3. I am copy pasting your data here -
%%5th input color ^

Image Analyst
Image Analyst 2022 年 7 月 31 日
This will do it:
osmotisk_data = readtable("tester_tabeller.xlsx")
x = osmotisk_data{:,1};
y = osmotisk_data{:,2};
z = osmotisk_data{:,3}
% surf(x,y,z,'linestyle','none','marker','o')
numPoints = size(z, 1)
% Make a colormap with, say, 256 potential colors.
numColors = 256;
cmap = jet(numColors)
% Get the rows of the colormap that each value of z should take on.
colorIndex = round(rescale(z, 1, numColors))
for k = 1 : numPoints
thisColor = cmap(colorIndex(k), :)
plot3(x(k), y(k), z(k),'.', 'Color', thisColor, 'MarkerSize', 100)
hold on;
fontSize = 20;
xlabel('x', 'FontSize',fontSize);
ylabel('y', 'FontSize',fontSize);
zlabel('z', 'FontSize',fontSize);
grid on
Note that the color of the spot corresponds to the value of Z.

Community Treasure Hunt

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

Start Hunting!

Translated by