Unable to set the scatter3 marker color using clim

조회 수: 14 (최근 30일)
Milos
Milos 2023년 1월 22일
댓글: Star Strider 2023년 1월 23일
I'm trying to set the scatter3 plot markers' colors based on the maximum range of z variables, using clim. No matter what I do, all markers always plot in the default color.
Tz = readtable("data.xlsx","Sheet","z");
[m,n] = size(Tz);
[Tzmin, Tzminidx] = min(Tz{:,2:n}); % the first column needs to be discarded for some reason
[Tzmax, Tzmaxidx] = max(Tz{:,2:n});
r = 75; % this will later change in a loop, thus I want the color range to be fixed
x = readtable("data.xlsx","Sheet","x");
x = table2array(x(r,2:n));
y = readtable("data.xlsx","Sheet","y");
y = table2array(y(r,2:n));
z = readtable("data.xlsx","Sheet","z");
z = table2array(z(r,2:n));
% all three sheets are of the same size m x n
scatter3(x, y, z, 'filled', 'MarkerEdgeColor', 'none');
set(gca,'clim',[Tzmin(1) Tzmax(n-1)]); % I want to fix this range based on the min and max values of z
view(-45,45);
colorbar();
The result is always:
Note, I'm always getting the default coloring, even without using clim. That is, even if I specify any colorbar, etc. I always get the default marker color.
What am I doing wrong? Thanks.

채택된 답변

Star Strider
Star Strider 2023년 1월 22일
편집: Star Strider 2023년 1월 22일
Perhaps something like this —
scatter3(x, y, z, 50, z, 'filled', 'MarkerEdgeColor', 'none');
The fourth argument to scatter3 is the marker size, and the fifth is the marker colour variable.
x = randn(1,150);
y = randn(1,150);
z = randn(1,150);
figure
scatter3(x, y, z, 50, z, 'filled', 'MarkerEdgeColor', 'none')
colormap(turbo)
colorbar
EDIT — Forgot colorbar. Fixed now.
.
  댓글 수: 2
Milos
Milos 2023년 1월 22일
Thank you for your answer and that pointer about which argument controls the color.
Your remarks together with the set command I used produced exactly what I was looking for.
Star Strider
Star Strider 2023년 1월 23일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by