How to specify any regions in a 3D-Plot with different colors
2 views (last 30 days)
Show older comments
Sam Kalho
on 22 Feb 2022
Commented: Sam Kalho
on 23 Feb 2022
Hallo all,
I need your help to solve my problem.
I wanted to create a 3D graph by coloring 3 specific regions with three different colors.
I have predicted deviations of a geometry from a component, now I want to show where deviations are equal and less than 0.5, where deviations are greater than 1, where deviations are between 0.5 and equal and less than 1.
I want to show:
for 'deviations.mat' <=0.5 then plotted with green.
for 'deviations.mat' > 1 then plotted with red.
for 0.5< 'deviations.mat' <=1 then plotted with yellow.
Could you please help me on this.
I would be very grateful to you guys.
Thank you in advance.
here is my full code:
clear all
close all
clc
load('X_achse_of_geometrie.mat');
load('Y_achse_of_geometrie.mat');
load('Z_achse_of_geometrie.mat');
load('deviations.mat')
axes1 = axes('Parent',figure,...
'Position',[0.128214285714286 0.157619047619049 0.775 0.784047619047622]);
plot3(x+denorm_pred, y+denorm_pred, z+denorm_pred ,'color', 'r');
zlabel('Z [mm]');
ylabel('Y [mm]');
xlabel('X [mm]');
title('component with deviations');
view(axes1,[-37.5 30]);
grid(axes1,'on');
legend1 = legend(axes1,'show');
set(legend1,...
'Position',[0.0508333333333333 0.884126986397638 0.180357140196221 0.0869047596341085]);
Thankls
0 Comments
Accepted Answer
Benjamin Thompson
on 22 Feb 2022
Use index vectors:
Igreen = denorm_pred < 0.5;
Ired = denorm_pred > 1;
Iyellow = denorm_pred >= 0.5 & denorm_pred <= 1;
plot3(x(Ired)+denorm_pred(Ired), y(Ired)+denorm_pred(Ired), z(Ired)+denorm_pred(Ired) ,'color', 'r');
hold on;
plot3(x(Igreen)+denorm_pred(Igreen), y(Igreen)+denorm_pred(Igreen), z(Igreen)+denorm_pred(Igreen) ,'color', 'g');
plot3(x(Iyellow)+denorm_pred(Iyellow), y(Iyellow)+denorm_pred(Iyellow), z(Iyellow)+denorm_pred(Iyellow) ,'color', 'y');
hold off;
More Answers (0)
See Also
Categories
Find more on Polar Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!