我有以下脚本:
clear; clc
close all
# input samples
samples = rand(100,2);
# gaussian mean and covariance
mu = mean(samples);
sigma = cov(samples);
# define a 2D grid
x1 = -3:.2:3;
x2 = -3:.2:3;
[X1,X2] = meshgrid(x1,x2);
X = [X1(:) X2(:)];
# evaluate the pdf at the grid points
y = mvnpdf(X,mu,sigma);
y = reshape(y,length(x2),length(x1));
# plot iso-contours
contour(x1,x2,y,[0.0001 0.001 0.01 0.05 0.15 0.25 0.35])
xlabel('x')
ylabel('y')
line([0 0 1 1 0],[1 0 0 1 1],'Linestyle','--','Color','k')
# plot samples
hold on
plot(samples(:,1),samples(:,2),'+')
如果我运行它,这是我得到的输出:
多数情况下都很好,除了绘制的点由框绘制轮廓。出于审美原因,我想移除那个盒子。
请,有人可以告诉我该怎么做吗?
答案 0 :(得分:1)
不是答案(因为已在注释中得到答案),但将其写为答案,因为很难将代码放入注释中。
我只是想说,因为您提到了“美学”,所以通常可以用最少的精力在图形演示中产生很大的不同。例如
clear; clc; clf
figure(1)
# input samples
samples = rand(100,2);
# gaussian mean and covariance
mu = mean(samples);
sigma = cov(samples);
# define a 2D grid
x1 = -3:.2:3;
x2 = -3:.2:3;
[X1,X2] = meshgrid(x1,x2);
X = [X1(:) X2(:)];
# evaluate the pdf at the grid points
y = mvnpdf(X,mu,sigma);
y = reshape(y,length(x2),length(x1));
# plot iso-contours
contour(x1,x2,y,[0.0001 0.001 0.01 0.05 0.15 0.25 0.35], 'linewidth', 3);
set(gcf, 'color', [0.75,0.75,0.75]);
set(gca, 'color', 'k');
xlabel('x')
ylabel('y')
# plot samples
hold on
h = plot(samples(:,1),samples(:,2), 'o', 'markerfacecolor', [0, 0.6, 1], ...
'markeredgecolor', [0, .4, .8], 'linewidth', 1.5, 'markersize', 7);
axis tight auto equal square;