Matlab画出漂亮的三维散点图

load('modeltestdata')j加载作图数据,其中仅包含一个名为“num”的二维数组

作图数据 “num” 为8行,11列的一个二维数组,第一列为x轴坐标,第二列为y轴坐标,第3到11列为9组z轴坐标

作图时删掉第一列表头

X-axis Y-aixs V=0.15 0.23 0.35 0.45 0.55 0.65 0.75 0.85 1
9 -9 95.36 94.9 92.16 90.62 87.55 85.43 83.25 79.95 75.61
5 -5 81.93 80.02 77.58 75.64 73.75 71.64 69.59 67.92 64.57
0 0 67.02 65.12 62.68 59.93 57.1 53.6 50.59 46.58 43.38
5 0 81.26 79.55 76.35 75.83 73.58 71.65 69.18 67.65 63.92
7 0 89.64 89.46 86.63 85.98 83.74 81.92 79.78 78.5 74.94
9 0 95.8 95.04 93.44 91.07 90.62 87.78 85.91 82.98 77.5
5 5 83.89 81.15 78.91 77.85 76.4 74.53 73.09 71.07 67.59
9 9 96.65 95.44 94 92.98 91.49 89.87 87.76 84.97 78.61

clear
clc
close all

load('modeltestdata')

V_015 = num(1:8,3);
V_023 = num(1:8,4);
V_035 = num(1:8,5);
V_045 = num(1:8,6);
V_055 = num(1:8,7);
V_065 = num(1:8,8);
V_075 = num(1:8,9);
V_085 = num(1:8,10);
V_100 = num(1:8,11);

color_light = [0, 1, 1];    %设置渐变色的浅色 三个数为matlab中的颜色的RGB数值
color_dark = [0.5 0 0];         %设置渐变色的深色

dataNum = 9;        %有几组渐变颜色的数据

colour_col1 = (color_light(1) : (color_dark(1)-color_light(1))/(dataNum-1) : color_dark(1))';
colour_col2 = (color_light(2) : (color_dark(2)-color_light(2))/(dataNum-1) : color_dark(2))';
colour_col3 = (color_light(3) : (color_dark(3)-color_light(3))/(dataNum-1) : color_dark(3))';
colour = [colour_col1,colour_col2,colour_col3];

x_axis = num(1:8,1);    
y_axis = num(1:8,2);    

figure(1);
p1 = scatter3(x_axis, y_axis, V_015, 36, colour(1,:), 'filled');
hold on
p2 = scatter3(x_axis, y_axis, V_023, 36, colour(2,:), 'filled');
hold on
p3 = scatter3(x_axis, y_axis, V_035, 36, colour(3,:), 'filled');
hold on
p4 = scatter3(x_axis, y_axis, V_045, 36, colour(4,:), 'filled');
hold on
p5 = scatter3(x_axis, y_axis, V_055, 36, colour(5,:), 'filled');
hold on
p6 = scatter3(x_axis, y_axis, V_065, 36, colour(6,:), 'filled');
hold on
p7 = scatter3(x_axis, y_axis, V_075, 36, colour(7,:), 'filled');
hold on
p8 = scatter3(x_axis, y_axis, V_085, 36, colour(8,:), 'filled');
hold on
p9 = scatter3(x_axis, y_axis, V_100, 36, colour(9,:), 'filled');

%绘制投影点
projectSpot = 30 * ones(8,1);
hold on 
plot3(x_axis, y_axis, projectSpot, '*');

%投影辅助线绘制
assistLine1_z = num(1,3:11)';
assistLine1_z(9,1) = 30;
assistLine1_x = num(1,1) * ones(9,1);
assistLine1_y = num(1,2) * ones(9,1);
hold on 
plot3(assistLine1_x, assistLine1_y, assistLine1_z, '--b')

assistLine2_z = num(2,3:11)';
assistLine2_z(9,1) = 30;
assistLine2_x = num(2,1) * ones(9,1);
assistLine2_y = num(2,2) * ones(9,1);
hold on 
plot3(assistLine2_x, assistLine2_y, assistLine2_z, '--b')

assistLine3_z = num(3,3:11)';
assistLine3_z(9,1) = 30;
assistLine3_x = num(3,1) * ones(9,1);
assistLine3_y = num(3,2) * ones(9,1);
hold on 
plot3(assistLine3_x, assistLine3_y, assistLine3_z, '--b')

assistLine4_z = num(4,3:11)';
assistLine4_z(9,1) = 30;
assistLine4_x = num(4,1) * ones(9,1);
assistLine4_y = num(4,2) * ones(9,1);
hold on 
plot3(assistLine4_x, assistLine4_y, assistLine4_z, '--b')

assistLine5_z = num(5,3:11)';
assistLine5_z(9,1) = 30;
assistLine5_x = num(5,1) * ones(9,1);
assistLine5_y = num(5,2) * ones(9,1);
hold on 
plot3(assistLine5_x, assistLine5_y, assistLine5_z, '--b')

assistLine6_z = num(6,3:11)';
assistLine6_z(9,1) = 30;
assistLine6_x = num(6,1) * ones(9,1);
assistLine6_y = num(6,2) * ones(9,1);
hold on 
plot3(assistLine6_x, assistLine6_y, assistLine6_z, '--b')

assistLine7_z = num(7,3:11)';
assistLine7_z(9,1) = 30;
assistLine7_x = num(7,1) * ones(9,1);
assistLine7_y = num(7,2) * ones(9,1);
hold on 
plot3(assistLine7_x, assistLine7_y, assistLine7_z, '--b')

assistLine8_z = num(8,3:11)';
assistLine8_z(9,1) = 30;
assistLine8_x = num(8,1) * ones(9,1);
assistLine8_y = num(8,2) * ones(9,1);
hold on 
plot3(assistLine8_x, assistLine8_y, assistLine8_z, '--b')

%设置坐标轴lable
x1=xlabel('上游推进器角度(°)'); %x轴标题
x2=ylabel('下游推进器角度(°)'); %y轴标题
x3=zlabel('下游推进器螺旋桨推力(N)'); %z轴标题
set(x1,'position', [5 -3 10], 'Rotation',4); %x轴名称旋转
set(x2,'position', [0.5 1 10], 'Rotation',-42); %y轴名称旋转

%设置图例
legend([p1(1),p2(1),p3(1),p4(1),p5(1),p6(1),p7(1),p8(1),p9(1)],'V=0.15m/s','V=0.23m/s','V=0.35m/s','V=0.45m/s','V=0.55m/s','V=0.65m/s','V=0.75m/s','V=0.85m/s','V=1.00m/s'...
    , 'Location', 'best')

%设置图片显示角度
view(-19,22)

%保存图片
saveas(gcf, 'modeltest_Tp.svg')
disp('Picture is successfully saved!')

 

Matlab画出漂亮的三维散点图