Why am I not getting a colorcoded plot?
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi
I dont understand why I am not getting a colorcoded plot, it shd be colorcoded with the z-values but it isnt
댓글 수: 0
답변 (2개)
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 -
x=[500;600;400];
y=[1;2;3];
z=[0.9;0.7;0.1];
scatter3(x,y,z,20,x,'filled')
%%5th input color ^
colorbar
댓글 수: 0
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;
end
colormap(cmap);
colorbar
fontSize = 20;
xlabel('x', 'FontSize',fontSize);
ylabel('y', 'FontSize',fontSize);
zlabel('z', 'FontSize',fontSize);
grid on
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1083955/image.png)
Note that the color of the spot corresponds to the value of Z.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Purple에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!