plot cluster from matlab to python

3 次查看(过去 30 天)
sam mohel
sam mohel 2021-2-16
编辑: sam mohel 2021-2-16
i'm new to matlab.. and started to plot data into clusters shape like this image
the code i have written by matlab as
cmap=colormap;
for i=1:NCLUST
ic=int8((i*64.)/(NCLUST*1.));
subplot(2,1,1)
hold on
plot(rho(icl(i)),delta(icl(i)),'o','MarkerSize',8,'MarkerFaceColor',cmap(ic,:),'MarkerEdgeColor',cmap(ic,:));
end
subplot(2,1,2)
disp('Performing 2D nonclassical multidimensional scaling')
Y1 = mdscale(dist, 2, 'criterion','metricstress');
plot(Y1(:,1),Y1(:,2),'o','MarkerSize',2,'MarkerFaceColor','k','MarkerEdgeColor','k');
title ('2D Nonclassical multidimensional scaling','FontSize',15.0)
xlabel ('X')
ylabel ('Y')
for i=1:ND
A(i,1)=0.;
A(i,2)=0.;
end
for i=1:NCLUST
nn=0;
ic=int8((i*64.)/(NCLUST*1.));
for j=1:ND
if (halo(j)==i)
nn=nn+1;
A(nn,1)=Y1(j,1);
A(nn,2)=Y1(j,2);
end
end
hold on
plot(A(1:nn,1),A(1:nn,2),'o','MarkerSize',2,'MarkerFaceColor',cmap(ic,:),'MarkerEdgeColor',cmap(ic,:));
end
faa = fopen('CLUSTER_ASSIGNATION', 'w');
for i=1:ND
fprintf(faa, '%i %i %i\n',i,cl(i),halo(i));
end
and what i did in python like this
for i in range(NCLUST):
ic=int8((i*64.)/(NCLUST*1.))
plt.subplot(2,1,1)
plt.plot(rho[icl[i]],delta[icl[i]],marker='o',markersize=8,markerfacecolor='blue',color='green')
plt.subplot(2,1,2)
print('Performing 2D nonclassical multidimensional scaling')
Y1 = mdscale(dist, 2, 'criterion','metricstress')
plt.plot(Y1[:,1],Y1[:,2],marker='o',markersize=2,markerfacecolor='black',markeredgecolor='black')
title ('2D Nonclassical multidimensional scaling','FontSize',15.0)
xlabel ('X')
ylabel ('Y')
for i in range(ND):
A[i,1]=0.
A[i,2]=0.
for i in range(NCLUST):
nn=0;
ic=int8((i*64.)/(NCLUST*1.))
for j in range (ND):
if (halo[j]==i):
nn=nn+1;
A[nn,1]=Y1[j,1]
A[nn,2]=Y1[j,2]
plt.show()
plt.plot(A[1:nn,1],A[1:nn,2],marker='o',markersize=2,markerfacecolor='black',markeredgecolor='black')
with open ('CLUSTER_ASSIGNATION', 'w') as faa:
print('Generated file:CLUSTER_ASSIGNATION')
print('column 1:element id')
print('column 2:cluster assignation without halo control')
print('column 3:cluster assignation with halo control')
for i in range (ND):
print('%i %i %i\n',i,cl[i],halo[i],file=faa)
but got error with blank image
MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
plt.subplot(2,1,1)
Performing 2D nonclassical multidimensional scaling
Traceback (most recent call last):
Y1 = mdscale(dist, 2, 'criterion','metricstress')
NameError: name 'mdscale' is not defined

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Call Python from MATLAB 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by