聚类分析树状图的初探

参考官方文档:https://docs.scipy.org/doc/scipy/reference/index.html

  此次使用聚类分析是因为文章需要,然后参考官方文档简单制作满足分析要求的树状图。

  因为到时候在A4纸上需要把三个图排版一下,所以在输出的时候就把图片设置的比较小。

 1 import pandas as pd
 2 import matplotlib.pyplot as plt
 3 from scipy.cluster import hierarchy
 4 
 5 plt.rcParams['font.sans-serif'] = ['SimHei'] #解决中文显示
 6 plt.rcParams['axes.unicode_minus'] = False #解决符号无法显示
 7 #设置颜色
 8 #hierarchy.set_link_color_palette(['m', 'c', 'y', 'k'])
 9 
10 df = pd.read_excel('品种日产量聚类.xlsx',sheet_name='zaoju')
11 fig, axes = plt.subplots(1,figsize=(4,4))
12 Z = hierarchy.linkage(df,'centroid',metric='euclidean')
13 names = ['E1','E2','E3','E4','E5','E6','E7','E8','E9','E10','E11','E12','E13','E14','E15','E16','E17','E18','E19','E20','E21','E22','E23','E24','E25','E26','E27','E28']
14 
15 dn=hierarchy.dendrogram(Z,orientation='right',labels=names)
16 print(dn['color_list'])
17 
18 plt.show()
19 #plt.savefig('早稻聚类01.jpg',dpi=300)
早稻聚类分析

 

 1 import pandas as pd
 2 import matplotlib.pyplot as plt
 3 from scipy.cluster import hierarchy
 4 
 5 fig, axes = plt.subplots(1,figsize=(4,4))
 6 
 7 # 晚粳聚
 8 df3 = pd.read_excel('品种日产量聚类.xlsx',sheet_name='晚粳聚')
 9 Z3 = hierarchy.linkage(df3,'centroid',metric='euclidean')
10 names3 = ['L24','L25','L26','L27','L28','L29',
11           'L30','L31','L32','L33','L34','L35',
12           'L36','L37','L38','L39','L40','L41',
13           'L42','L43','L44','L45','L46','L47','L48','L49']
14 dn3=hierarchy.dendrogram(Z3,orientation='right',labels=names3)
15 #dn3=hierarchy.dendrogram(Z3,orientation='right')
16 #plt.show()
17 plt.savefig('晚粳聚01.jpg',dpi=300)
晚粳聚

 

 1 import pandas as pd
 2 import matplotlib.pyplot as plt
 3 from scipy.cluster import hierarchy
 4 
 5 fig, axes = plt.subplots(1,figsize=(4,4))
 6 
 7 # 晚籼聚
 8 df2 = pd.read_excel('品种日产量聚类.xlsx',sheet_name='晚籼聚')
 9 Z2 = hierarchy.linkage(df2,'centroid',metric='euclidean')
10 names2 = ['L1','L2','L3','L4','L5','L6','L7',
11           'L8','L9','L10','L11','L12','L13','L14',
12           'L15','L16','L17','L18','L19','L20','L21',
13          'L22','23']
14 dn2=hierarchy.dendrogram(Z2,orientation='right',labels=names2)
15 
16 #plt.show()
17 plt.savefig('晚籼01.jpg',dpi=300)
晚籼聚

转载于:https://www.cnblogs.com/canvas2018/p/10478232.html

你可能感兴趣的:(人工智能,python)