我想在Matlab中创建一个'blob'类型的绘图,如下面的链接所示。
这种类型的绘图在Matlab中是否可行?我在考虑轮廓图。
答案 0 :(得分:3)
使用样条插值可以得到类似的结果。在这个例子中,我复制了x1和y1向量的值,以避免在插值形状上产生不连续性。不幸的是,Octave的fill
功能无法处理透明度,因此您可以自由调整此代码以添加此选项。
n = 1000; % # of interpolation points.
p = 5 % # of label
lab = {'text1','text2','text3','text4','text5'} % label
theta = linspace(0,2*pi-(2*pi)/p,p); % The angle
thetal = [theta(1),theta(end:-1:2)]; % Theta for placement of labels
rho = [0.65 0.8 0.7 0.9 1] % The spider graph values
[x1,y1] = pol2cart(theta,rho)
x1 = repmat(x1,1,10);
y1 = repmat(y1,1,10);
如下图所示,如果我不复制x1和y1向量,我将在计算插值时获得一些不连续性:
t = [0,cumsum(sqrt(diff(x1).^2+diff(y1).^2))]; %cumsum(euclidian distance) => t(end) = perimeter.
ti = linspace(0,t(end),n);
x = interp1(t,x1,ti,'spline');
y = interp1(t,y1,ti,'spline');
%We plot the interpolated shape
fill(x(round(0.5*n):round(0.6*n)),y(round(0.5*n):round(0.6*n)),[0.2,0.2,0.2]) %you need to start to fill your interpolated shape at another point than the first and last point if you want to avoid a discontinuity.
hold on
%Then we plot a circle and some other stuff
set(gca,'Color',[0.6 0.6 0.6]);
%plot(0,0,'bo')
plot(x1,y1,'o','Color',[0.4,0.4,0.4],'MarkerSize',3,'MarkerFaceColor','auto')
plot(sin(0:0.1:2*pi+0.1),cos(0:0.1:2*pi+0.1),'Color',[0.4,0.4,0.4],'linewidth',3)
for i = 1:p
plot([0,sin(theta(i)+pi/2)],[0,cos(theta(i)+pi/2)],'Color',[0.4,0.4,0.4],'linewidth',3);
h(i) = text(sin(theta(i)+pi/2),cos(theta(i)+pi/2),lab{i});
set(h(i), 'rotation', rad2deg(thetal(i))-90,'HorizontalAlignment','center','VerticalAlignment','bottom')
end
ylim([-1.2,1.2])
xlim([-1.2,1.2])
axis equal
<强> RESULT 强>