예제 #1
0
파일: draw.py 프로젝트: ThomasWork/school
sns.set(font_scale=1.5,font='STSong')
flights_long = pd.read_csv(fu.getCurPathAndName('data.csv'), encoding="utf-8")
flights = flights_long.pivot(u"from", u"to", u"rate")

order=[u'三里屯',u'后海',u'雍和宫',u'故宫',u'天安门广场',u'798艺术区',u'鸟巢',u'颐和园',u'国际机场',u'世贸天阶']

flights = flights.reindex(index=order, columns=order)

#flights.index = pd.CategoricalIndex(flights.index, categories= )
#flights.sortlevel(level=0, inplace=True)

print flights

# 绘制x-y-z的热力图,比如 年-月-销量 的热力图
f, ax = plt.subplots(figsize=(9, 8))
#绘制热力图,还要将数值写到热力图上
#每个网格上用线隔开
#sns.heatmap(flights, annot=True, annot_kws={"size": 7})
sns.heatmap(flights, annot=True, fmt=".2f", linewidths=.1, ax=ax, cmap="YlOrRd")#, cbar=False)
#设置坐标字体方向
label_y = ax.get_yticklabels()
plt.setp(label_y, rotation=360, horizontalalignment='right')

label_x = ax.get_xticklabels()
plt.setp(label_x, rotation=30, horizontalalignment='right')
plt.show()
plt.tight_layout()
fig=plt.figure()
mc.saveFig(fig)
예제 #2
0
파일: draw.py 프로젝트: ThomasWork/school
X = np.random.randn(833, 1)
for i in range(len(X)):
	X[i] = i + 0.1
print X

#fclust1 = fclusterdata(X, 1.0, metric=mydist2)

Z = linkage(X, 'average', metric=mydist2)
c, coph_dists = cophenet(Z, pdist(X))
print c
#print Z
#print Z[-2:,2]
plt.figure(figsize=(8, 6))
#plt.title(u'外地游客访问路径层次聚类结果')
plt.xlabel(u'路径下标')
plt.ylabel(u'类间距离')
#dendrogram(Z, leaf_rotation=90., leaf_font_size=8.)
dendrogram(Z, truncate_mode='lastp', p=300, leaf_rotation=0., leaf_font_size=12., show_contracted=True)
max_d = 0.4
#plt.axhline(y=max_d, c='r')
#fancy_dendrogram(Z, truncate_mode='lastp', p=20, leaf_rotation=90., leaf_font_size=12., show_contracted=True, annotate_above=10, max_d=0.3)
plt.tight_layout()
plt.show()
mc.saveFig(plt)
clusters = fcluster(Z, max_d, criterion='distance')
print clusters
curDir=fu.getCurDir()
np.savetxt(curDir+"/clusters.txt", clusters, fmt="%d", delimiter=",");


#参考网址:https://haojunsui.github.io/2016/07/16/scipy-hac/
예제 #3
0
파일: draw.py 프로젝트: ThomasWork/school
                       linewidth=0.1)
fig.colorbar(surf)
surf.set_clim(vmin=np.min(z), vmax=2)
#surf.set_edgecolors(surf.to_rgba(surf._A))
#surf.set_facecolors("white")

#ax.scatter(x, y, min(z), s=30, marker='o', cmap=cm)
#ax.scatter(x, y, z, s=30, marker='*', cmap=cm)

#for index in range(len(x)):
#pz=np.linspace(np.min(z), z[index], 50)
#px=[x[index]]*len(pz)
#py=[y[index]]*len(pz)
#ax.plot(px, py, pz)

#ax.set_axis_off()

ax.set_zlim3d(np.min(z), np.max(z))
#ax.set_xlim3d(0,1),
ax.set_xticks([])
#ax.set_ylim3d(0,1),
ax.set_yticks([])
#ax.set_zticks([])

plt.grid(True)
#ax.set_xlabel(u'位置', linespacing=3.2)
#zLabel = ax.set_zlabel('Local Density', linespacing=3.4)
#plt.title('Number of models processed per block')

mc.saveFig(plt, 'fig_choose_block.pdf')
plt.show()