MATLAB散点图、表面图、等高线图绘制命令

% Plot Data 散点图:程序实现绘制一个一Xy为数据,红色的x作为标记的散点图,标记大小为10,并加入横纵坐标轴的题目

 

plot(X, y, 'rx', 'MarkerSize', 10); % Plot the data

ylabel('Profit in $10,000s'); % Set the y?axis label

xlabel('Population of City in 10,000s'); % Set the x?axis label

--------------------------------------

MATLAB散点图、表面图、等高线图绘制命令_第1张图片

% Surface plot 表面图:程序以theta0_valstheta1_vals为两个变量,J_vals为结果绘制表面图。注:theta0_valstheta1_vals各为1*100的行向量,J_vals100*100的方阵


figure;

surf(theta0_vals, theta1_vals,J_vals)

xlabel('\theta_0'); ylabel('\theta_1');

-------------------------------------------------------

MATLAB散点图、表面图、等高线图绘制命令_第2张图片

% Contour plot 轮廓图,contour(x,y,z,v):其中xy为横纵坐标,z为等高线值的大小,同样x100*1y100*1z100*100;同时v向量规定了等高线的范围为(通过logspace函数取到10^-2 10^3,取20个值)


figure;

% Plot J_vals as 15contours spaced logarithmically between 0.01 and 100

contour(theta0_vals,theta1_vals, J_vals, logspace(-2, 3, 20))

xlabel('\theta_0'); ylabel('\theta_1');

hold on;

plot(theta(1), theta(2), 'rx', 'MarkerSize', 10, 'LineWidth', 2);

-------------------------------------------------------

MATLAB散点图、表面图、等高线图绘制命令_第3张图片






你可能感兴趣的:(Matlab)