Hướng dẫn save dendrogram python - cứu trăn dendrogram

The problem is not with your resolution, but the size of the image (or the size of the lines). Since i do not know how to change the linewidth in the dendogram plot, i will just go with the straight forward solution to make a HUGE image.

import scipy.cluster.hierarchy as hcluster
import scipy.spatial.distance as ssd
import matplotlib.pyplot as plt
import numpy as np

SimMatrix = np.random.random((600,600))
SimMatrix = SimMatrix+SimMatrix.T
SimMatrix = np.abs(SimMatrix-np.diag(np.diag(SimMatrix)))

distVec = ssd.squareform(SimMatrix)
linkage = hcluster.linkage(distVec) #Changed here do NOT C+P back
plt.figure(figsize=(150,150))
dendro  = hcluster.dendrogram(linkage, leaf_rotation=90., leaf_font_size=0.5,)

plt.savefig('plt.png', format='png', bbox_inches='tight')
plt.savefig('plt.jpg', format='jpg', bbox_inches='tight')

The saved images looked bad for me, when i opened them, and only zooming in cleared up the problem. But the inlined plot in the jupyter notebook looked good, so maybe you only have to play with the format a bit.

This is probably not the best solution, but for me it worked. Hope someone else more competent can give you the correct solution too!

Ps.: Do not try to save these with 520 DPI, would break the pyplot.

Bạn có thể sử dụng

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
1 thay vì
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
2 vì bạn có thể biết nó sẽ chiếm bao nhiêu lưới

from scipy.cluster.hierarchy import linkage
from scipy.cluster.hierarchy import dendrogram
from scipy.spatial.distance import pdist
import matplotlib
from matplotlib import pyplot as plt
import numpy as np
from numpy import arange

# Create the figure and set it's size.
fig = plt.figure(figsize=(5,7))

# Create the first subplot in the figure. 
ax1 = plt.subplot2grid((3, 1), (0, 0), rowspan= 1, colspan=1)

# Set to your favorite colormap.
cm = matplotlib.cm.viridis

# Create array of random numbers.
X = np.random.random([6,300])

# Create a linkage object.
linkmat = linkage(X)

# Make a dendrogram from the linkage object.
dendrogram(linkmat)

# Use the x and y limits to set the aspect.
x0,x1 = ax1.get_xlim()
y0,y1 = ax1.get_ylim()
#ax1.set_aspect((x1-x0)/(y1-y0))


# Remove the ticks on the x-axis. 
plt.tick_params(axis='x', which='both', bottom='off', top='off', labelbottom='off')

# Create the second subplot.
ax2 = plt.subplot2grid((3, 1), (1, 0), rowspan= 2, colspan=1)

labels = ["a", "b", "c", "d", "e"]

plt.xticks(arange(0.5, 7.5, 1))

plt.gca().set_xticklabels(labels)

plt.pcolor(X.T)

x0,x1 = ax2.get_xlim()
y0,y1 = ax2.get_ylim()

#ax2.set_aspect((x1-x0)/(y1-y0))

# Insert the color scale
plt.colorbar()
cb = plt.colorbar(ax=ax1)
cb.ax.set_visible(False)

# Make the vertical distance between plots equal to zero 
plt.subplots_adjust(hspace=0)

# Show the plot
plt.show()


Để điều chỉnh chiều dài nhánh của dendrogram trong matplotlib, chúng ta có thể thực hiện các bước sau -

  • Đặt kích thước hình và điều chỉnh phần đệm giữa và xung quanh các ô con.

  • Vẽ các mẫu ngẫu nhiên (A và B) từ phân phối bình thường đa biến.a and b) from a multivariate normal distribution.a and b) from a multivariate normal distribution.

  • Tham gia một chuỗi các mảng dọc theo một trục hiện có, sử dụng phương thức Concatenate ().concatenate() method.concatenate() method.

  • Thực hiện phân cụm phân cấp/kết tụ.

  • Tạo một hình mới hoặc kích hoạt một hình hiện tại bằng phương thức Hình ().figure() method.figure() method.

  • Thêm một trục vào hình như là một phần của sự sắp xếp phụ.

  • Vẽ sơ đồ phân cụm phân cấp như một dendrogram bằng phương thức dendrogram ().dendrogram() method.dendrogram() method.

  • Để hiển thị hình, sử dụng phương thức show ().show() method.show() method.

Thí dụ

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()

Đầu ra

Cập nhật vào ngày 03 tháng 6 năm 2021 12:32:56

  • Câu hỏi và câu trả lời liên quan
  • Làm thế nào để điều chỉnh kích thước của hộp huyền thoại matplotlib?
  • Điều chỉnh chiều rộng của hộp trong Boxplot trong Python matplotlib
  • Làm cách nào để điều chỉnh (bù) Tiêu đề ColorBar trong matplotlib?
  • Vẽ hai mảng khác nhau có độ dài khác nhau trong matplotlib
  • Làm thế nào để điều chỉnh không gian giữa các dấu hiệu huyền thoại và nhãn trong matplotlib?
  • Làm thế nào để điều chỉnh độ trong suốt (alpha) trong cặp Seeborn bằng cách sử dụng matplotlib?
  • Làm thế nào để tạo một dendrogram cụm phân cấp trong r?
  • Làm thế nào để điều chỉnh sự sắp xếp của văn bản trong javafx?
  • Làm thế nào để điều chỉnh không gian giữa các ô phụ matplotlib/seeborn cho bố cục nhiều lô?
  • Làm thế nào để tạo một dendrogram mà không có nhãn trục x trong r?
  • Làm thế nào để điều chỉnh độ sáng của một hình ảnh trong Pytorch?
  • Làm thế nào để điều chỉnh độ tương phản của một hình ảnh trong Pytorch?
  • Làm thế nào để điều chỉnh màu sắc của một hình ảnh trong Pytorch?
  • Làm thế nào để điều chỉnh độ sắc nét của một hình ảnh trong Pytorch?
  • Làm thế nào để điều chỉnh 'tần số đánh dấu' trong matplotlib cho trục x chuỗi x?
scipy.cluster.hierarchy.dendrogram (z, p = 30, truncate_mode = none, color_threshold = none, get_leaves = true Sai, no_labels = false, leaf_font_size = nonedendrogram(Z, p=30, truncate_mode=None, color_threshold=None, get_leaves=True, orientation='top', labels=None, count_sort=False, distance_sort=False, show_leaf_counts=True, no_plot=False, no_labels=False, leaf_font_size=None, leaf_rotation=None, leaf_label_func=None, show_contracted=False, link_color_func=None, ax=None, above_threshold_color='C0')[source]#dendrogram(Z, p=30, truncate_mode=None, color_threshold=None, get_leaves=True, orientation='top', labels=None, count_sort=False, distance_sort=False, show_leaf_counts=True, no_plot=False, no_labels=False, leaf_font_size=None, leaf_rotation=None, leaf_label_func=None, show_contracted=False, link_color_func=None, ax=None, above_threshold_color='C0')[source]#

V số phân cụm phân cấp như một dendrogram.

Dendrogram minh họa cách mỗi cụm được sáng tác bằng cách vẽ một liên kết hình chữ U giữa một cụm không phải là Singleton và các con của nó. Phần trên của liên kết U biểu thị sự hợp nhất cụm. Hai chân của liên kết U cho biết cụm nào được hợp nhất. Chiều dài của hai chân của liên kết U biểu thị khoảng cách giữa các cụm trẻ em. Nó cũng là khoảng cách cophenetic giữa các quan sát ban đầu trong hai cụm trẻ em.

Tham số zndarrayZndarrayZndarray

Ma trận liên kết mã hóa phân cụm phân cấp để kết xuất dưới dạng dendrogram. Xem chức năng

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
3 để biết thêm thông tin về định dạng của

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
0.pint, tùy chọnint, optionalpint, tùy chọnint, optional

Tham số

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
1 cho
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
2.cắt ngắn_modestr, tùy chọnstr, optionalcắt ngắn_modestr, tùy chọnstr, optional

Dendrogram có thể khó đọc khi ma trận quan sát ban đầu mà từ đó liên kết có nguồn gốc lớn. Cắt ngắn được sử dụng để ngưng tụ dendrogram. Có một số chế độ:

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
3

Không có cắt được thực hiện (mặc định). Lưu ý:

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
4 là bí danh cho
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
3 mà Lừa giữ cho khả năng tương thích ngược.
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
6

Các cụm không singleton cuối cùng được hình thành trong liên kết là các nút không lá duy nhất trong liên kết; Chúng tương ứng với các hàng

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
8 trong
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
0. Tất cả các cụm không singleton khác được ký hợp đồng vào các nút lá.
from scipy.cluster.hierarchy import linkage
from scipy.cluster.hierarchy import dendrogram
from scipy.spatial.distance import pdist
import matplotlib
from matplotlib import pyplot as plt
import numpy as np
from numpy import arange

# Create the figure and set it's size.
fig = plt.figure(figsize=(5,7))

# Create the first subplot in the figure. 
ax1 = plt.subplot2grid((3, 1), (0, 0), rowspan= 1, colspan=1)

# Set to your favorite colormap.
cm = matplotlib.cm.viridis

# Create array of random numbers.
X = np.random.random([6,300])

# Create a linkage object.
linkmat = linkage(X)

# Make a dendrogram from the linkage object.
dendrogram(linkmat)

# Use the x and y limits to set the aspect.
x0,x1 = ax1.get_xlim()
y0,y1 = ax1.get_ylim()
#ax1.set_aspect((x1-x0)/(y1-y0))


# Remove the ticks on the x-axis. 
plt.tick_params(axis='x', which='both', bottom='off', top='off', labelbottom='off')

# Create the second subplot.
ax2 = plt.subplot2grid((3, 1), (1, 0), rowspan= 2, colspan=1)

labels = ["a", "b", "c", "d", "e"]

plt.xticks(arange(0.5, 7.5, 1))

plt.gca().set_xticklabels(labels)

plt.pcolor(X.T)

x0,x1 = ax2.get_xlim()
y0,y1 = ax2.get_ylim()

#ax2.set_aspect((x1-x0)/(y1-y0))

# Insert the color scale
plt.colorbar()
cb = plt.colorbar(ax=ax1)
cb.ax.set_visible(False)

# Make the vertical distance between plots equal to zero 
plt.subplots_adjust(hspace=0)

# Show the plot
plt.show()
20

Không nhiều hơn mức

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
1 của cây dendrogram được hiển thị. Một cấp độ của người Viking bao gồm tất cả các nút với
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
1 hợp nhất từ ​​sự hợp nhất cuối cùng.

Lưu ý:

from scipy.cluster.hierarchy import linkage
from scipy.cluster.hierarchy import dendrogram
from scipy.spatial.distance import pdist
import matplotlib
from matplotlib import pyplot as plt
import numpy as np
from numpy import arange

# Create the figure and set it's size.
fig = plt.figure(figsize=(5,7))

# Create the first subplot in the figure. 
ax1 = plt.subplot2grid((3, 1), (0, 0), rowspan= 1, colspan=1)

# Set to your favorite colormap.
cm = matplotlib.cm.viridis

# Create array of random numbers.
X = np.random.random([6,300])

# Create a linkage object.
linkmat = linkage(X)

# Make a dendrogram from the linkage object.
dendrogram(linkmat)

# Use the x and y limits to set the aspect.
x0,x1 = ax1.get_xlim()
y0,y1 = ax1.get_ylim()
#ax1.set_aspect((x1-x0)/(y1-y0))


# Remove the ticks on the x-axis. 
plt.tick_params(axis='x', which='both', bottom='off', top='off', labelbottom='off')

# Create the second subplot.
ax2 = plt.subplot2grid((3, 1), (1, 0), rowspan= 2, colspan=1)

labels = ["a", "b", "c", "d", "e"]

plt.xticks(arange(0.5, 7.5, 1))

plt.gca().set_xticklabels(labels)

plt.pcolor(X.T)

x0,x1 = ax2.get_xlim()
y0,y1 = ax2.get_ylim()

#ax2.set_aspect((x1-x0)/(y1-y0))

# Insert the color scale
plt.colorbar()
cb = plt.colorbar(ax=ax1)
cb.ax.set_visible(False)

# Make the vertical distance between plots equal to zero 
plt.subplots_adjust(hspace=0)

# Show the plot
plt.show()
23 là bí danh cho
from scipy.cluster.hierarchy import linkage
from scipy.cluster.hierarchy import dendrogram
from scipy.spatial.distance import pdist
import matplotlib
from matplotlib import pyplot as plt
import numpy as np
from numpy import arange

# Create the figure and set it's size.
fig = plt.figure(figsize=(5,7))

# Create the first subplot in the figure. 
ax1 = plt.subplot2grid((3, 1), (0, 0), rowspan= 1, colspan=1)

# Set to your favorite colormap.
cm = matplotlib.cm.viridis

# Create array of random numbers.
X = np.random.random([6,300])

# Create a linkage object.
linkmat = linkage(X)

# Make a dendrogram from the linkage object.
dendrogram(linkmat)

# Use the x and y limits to set the aspect.
x0,x1 = ax1.get_xlim()
y0,y1 = ax1.get_ylim()
#ax1.set_aspect((x1-x0)/(y1-y0))


# Remove the ticks on the x-axis. 
plt.tick_params(axis='x', which='both', bottom='off', top='off', labelbottom='off')

# Create the second subplot.
ax2 = plt.subplot2grid((3, 1), (1, 0), rowspan= 2, colspan=1)

labels = ["a", "b", "c", "d", "e"]

plt.xticks(arange(0.5, 7.5, 1))

plt.gca().set_xticklabels(labels)

plt.pcolor(X.T)

x0,x1 = ax2.get_xlim()
y0,y1 = ax2.get_ylim()

#ax2.set_aspect((x1-x0)/(y1-y0))

# Insert the color scale
plt.colorbar()
cb = plt.colorbar(ax=ax1)
cb.ax.set_visible(False)

# Make the vertical distance between plots equal to zero 
plt.subplots_adjust(hspace=0)

# Show the plot
plt.show()
20 mà Lừa giữ cho khả năng tương thích ngược.color_thresholddouble, tùy chọndouble, optionalcolor_thresholddouble, tùy chọndouble, optional

Đối với sự ngắn gọn, hãy để \ (t \) là

from scipy.cluster.hierarchy import linkage
from scipy.cluster.hierarchy import dendrogram
from scipy.spatial.distance import pdist
import matplotlib
from matplotlib import pyplot as plt
import numpy as np
from numpy import arange

# Create the figure and set it's size.
fig = plt.figure(figsize=(5,7))

# Create the first subplot in the figure. 
ax1 = plt.subplot2grid((3, 1), (0, 0), rowspan= 1, colspan=1)

# Set to your favorite colormap.
cm = matplotlib.cm.viridis

# Create array of random numbers.
X = np.random.random([6,300])

# Create a linkage object.
linkmat = linkage(X)

# Make a dendrogram from the linkage object.
dendrogram(linkmat)

# Use the x and y limits to set the aspect.
x0,x1 = ax1.get_xlim()
y0,y1 = ax1.get_ylim()
#ax1.set_aspect((x1-x0)/(y1-y0))


# Remove the ticks on the x-axis. 
plt.tick_params(axis='x', which='both', bottom='off', top='off', labelbottom='off')

# Create the second subplot.
ax2 = plt.subplot2grid((3, 1), (1, 0), rowspan= 2, colspan=1)

labels = ["a", "b", "c", "d", "e"]

plt.xticks(arange(0.5, 7.5, 1))

plt.gca().set_xticklabels(labels)

plt.pcolor(X.T)

x0,x1 = ax2.get_xlim()
y0,y1 = ax2.get_ylim()

#ax2.set_aspect((x1-x0)/(y1-y0))

# Insert the color scale
plt.colorbar()
cb = plt.colorbar(ax=ax1)
cb.ax.set_visible(False)

# Make the vertical distance between plots equal to zero 
plt.subplots_adjust(hspace=0)

# Show the plot
plt.show()
25. Màu sắc tất cả các liên kết hạ xuống bên dưới một nút cụm \ (k \) cùng màu nếu \ (k \) là nút đầu tiên bên dưới ngưỡng cắt \ (t \). Tất cả các liên kết kết nối các nút có khoảng cách lớn hơn hoặc bằng ngưỡng được tô màu với màu matplotlib mặc định
from scipy.cluster.hierarchy import linkage
from scipy.cluster.hierarchy import dendrogram
from scipy.spatial.distance import pdist
import matplotlib
from matplotlib import pyplot as plt
import numpy as np
from numpy import arange

# Create the figure and set it's size.
fig = plt.figure(figsize=(5,7))

# Create the first subplot in the figure. 
ax1 = plt.subplot2grid((3, 1), (0, 0), rowspan= 1, colspan=1)

# Set to your favorite colormap.
cm = matplotlib.cm.viridis

# Create array of random numbers.
X = np.random.random([6,300])

# Create a linkage object.
linkmat = linkage(X)

# Make a dendrogram from the linkage object.
dendrogram(linkmat)

# Use the x and y limits to set the aspect.
x0,x1 = ax1.get_xlim()
y0,y1 = ax1.get_ylim()
#ax1.set_aspect((x1-x0)/(y1-y0))


# Remove the ticks on the x-axis. 
plt.tick_params(axis='x', which='both', bottom='off', top='off', labelbottom='off')

# Create the second subplot.
ax2 = plt.subplot2grid((3, 1), (1, 0), rowspan= 2, colspan=1)

labels = ["a", "b", "c", "d", "e"]

plt.xticks(arange(0.5, 7.5, 1))

plt.gca().set_xticklabels(labels)

plt.pcolor(X.T)

x0,x1 = ax2.get_xlim()
y0,y1 = ax2.get_ylim()

#ax2.set_aspect((x1-x0)/(y1-y0))

# Insert the color scale
plt.colorbar()
cb = plt.colorbar(ax=ax1)
cb.ax.set_visible(False)

# Make the vertical distance between plots equal to zero 
plt.subplots_adjust(hspace=0)

# Show the plot
plt.show()
26. Nếu \ (t \) nhỏ hơn hoặc bằng 0, tất cả các nút được tô màu
from scipy.cluster.hierarchy import linkage
from scipy.cluster.hierarchy import dendrogram
from scipy.spatial.distance import pdist
import matplotlib
from matplotlib import pyplot as plt
import numpy as np
from numpy import arange

# Create the figure and set it's size.
fig = plt.figure(figsize=(5,7))

# Create the first subplot in the figure. 
ax1 = plt.subplot2grid((3, 1), (0, 0), rowspan= 1, colspan=1)

# Set to your favorite colormap.
cm = matplotlib.cm.viridis

# Create array of random numbers.
X = np.random.random([6,300])

# Create a linkage object.
linkmat = linkage(X)

# Make a dendrogram from the linkage object.
dendrogram(linkmat)

# Use the x and y limits to set the aspect.
x0,x1 = ax1.get_xlim()
y0,y1 = ax1.get_ylim()
#ax1.set_aspect((x1-x0)/(y1-y0))


# Remove the ticks on the x-axis. 
plt.tick_params(axis='x', which='both', bottom='off', top='off', labelbottom='off')

# Create the second subplot.
ax2 = plt.subplot2grid((3, 1), (1, 0), rowspan= 2, colspan=1)

labels = ["a", "b", "c", "d", "e"]

plt.xticks(arange(0.5, 7.5, 1))

plt.gca().set_xticklabels(labels)

plt.pcolor(X.T)

x0,x1 = ax2.get_xlim()
y0,y1 = ax2.get_ylim()

#ax2.set_aspect((x1-x0)/(y1-y0))

# Insert the color scale
plt.colorbar()
cb = plt.colorbar(ax=ax1)
cb.ax.set_visible(False)

# Make the vertical distance between plots equal to zero 
plt.subplots_adjust(hspace=0)

# Show the plot
plt.show()
26. Nếu
from scipy.cluster.hierarchy import linkage
from scipy.cluster.hierarchy import dendrogram
from scipy.spatial.distance import pdist
import matplotlib
from matplotlib import pyplot as plt
import numpy as np
from numpy import arange

# Create the figure and set it's size.
fig = plt.figure(figsize=(5,7))

# Create the first subplot in the figure. 
ax1 = plt.subplot2grid((3, 1), (0, 0), rowspan= 1, colspan=1)

# Set to your favorite colormap.
cm = matplotlib.cm.viridis

# Create array of random numbers.
X = np.random.random([6,300])

# Create a linkage object.
linkmat = linkage(X)

# Make a dendrogram from the linkage object.
dendrogram(linkmat)

# Use the x and y limits to set the aspect.
x0,x1 = ax1.get_xlim()
y0,y1 = ax1.get_ylim()
#ax1.set_aspect((x1-x0)/(y1-y0))


# Remove the ticks on the x-axis. 
plt.tick_params(axis='x', which='both', bottom='off', top='off', labelbottom='off')

# Create the second subplot.
ax2 = plt.subplot2grid((3, 1), (1, 0), rowspan= 2, colspan=1)

labels = ["a", "b", "c", "d", "e"]

plt.xticks(arange(0.5, 7.5, 1))

plt.gca().set_xticklabels(labels)

plt.pcolor(X.T)

x0,x1 = ax2.get_xlim()
y0,y1 = ax2.get_ylim()

#ax2.set_aspect((x1-x0)/(y1-y0))

# Insert the color scale
plt.colorbar()
cb = plt.colorbar(ax=ax1)
cb.ax.set_visible(False)

# Make the vertical distance between plots equal to zero 
plt.subplots_adjust(hspace=0)

# Show the plot
plt.show()
25 là không có hoặc ‘mặc định, tương ứng với hành vi MATLAB (TM), ngưỡng được đặt thành
from scipy.cluster.hierarchy import linkage
from scipy.cluster.hierarchy import dendrogram
from scipy.spatial.distance import pdist
import matplotlib
from matplotlib import pyplot as plt
import numpy as np
from numpy import arange

# Create the figure and set it's size.
fig = plt.figure(figsize=(5,7))

# Create the first subplot in the figure. 
ax1 = plt.subplot2grid((3, 1), (0, 0), rowspan= 1, colspan=1)

# Set to your favorite colormap.
cm = matplotlib.cm.viridis

# Create array of random numbers.
X = np.random.random([6,300])

# Create a linkage object.
linkmat = linkage(X)

# Make a dendrogram from the linkage object.
dendrogram(linkmat)

# Use the x and y limits to set the aspect.
x0,x1 = ax1.get_xlim()
y0,y1 = ax1.get_ylim()
#ax1.set_aspect((x1-x0)/(y1-y0))


# Remove the ticks on the x-axis. 
plt.tick_params(axis='x', which='both', bottom='off', top='off', labelbottom='off')

# Create the second subplot.
ax2 = plt.subplot2grid((3, 1), (1, 0), rowspan= 2, colspan=1)

labels = ["a", "b", "c", "d", "e"]

plt.xticks(arange(0.5, 7.5, 1))

plt.gca().set_xticklabels(labels)

plt.pcolor(X.T)

x0,x1 = ax2.get_xlim()
y0,y1 = ax2.get_ylim()

#ax2.set_aspect((x1-x0)/(y1-y0))

# Insert the color scale
plt.colorbar()
cb = plt.colorbar(ax=ax1)
cb.ax.set_visible(False)

# Make the vertical distance between plots equal to zero 
plt.subplots_adjust(hspace=0)

# Show the plot
plt.show()
29.\(t\) be the
from scipy.cluster.hierarchy import linkage
from scipy.cluster.hierarchy import dendrogram
from scipy.spatial.distance import pdist
import matplotlib
from matplotlib import pyplot as plt
import numpy as np
from numpy import arange

# Create the figure and set it's size.
fig = plt.figure(figsize=(5,7))

# Create the first subplot in the figure. 
ax1 = plt.subplot2grid((3, 1), (0, 0), rowspan= 1, colspan=1)

# Set to your favorite colormap.
cm = matplotlib.cm.viridis

# Create array of random numbers.
X = np.random.random([6,300])

# Create a linkage object.
linkmat = linkage(X)

# Make a dendrogram from the linkage object.
dendrogram(linkmat)

# Use the x and y limits to set the aspect.
x0,x1 = ax1.get_xlim()
y0,y1 = ax1.get_ylim()
#ax1.set_aspect((x1-x0)/(y1-y0))


# Remove the ticks on the x-axis. 
plt.tick_params(axis='x', which='both', bottom='off', top='off', labelbottom='off')

# Create the second subplot.
ax2 = plt.subplot2grid((3, 1), (1, 0), rowspan= 2, colspan=1)

labels = ["a", "b", "c", "d", "e"]

plt.xticks(arange(0.5, 7.5, 1))

plt.gca().set_xticklabels(labels)

plt.pcolor(X.T)

x0,x1 = ax2.get_xlim()
y0,y1 = ax2.get_ylim()

#ax2.set_aspect((x1-x0)/(y1-y0))

# Insert the color scale
plt.colorbar()
cb = plt.colorbar(ax=ax1)
cb.ax.set_visible(False)

# Make the vertical distance between plots equal to zero 
plt.subplots_adjust(hspace=0)

# Show the plot
plt.show()
25. Colors all the descendent links below a cluster node \(k\) the same color if \(k\) is the first node below the cut threshold \(t\). All links connecting nodes with distances greater than or equal to the threshold are colored with de default matplotlib color
from scipy.cluster.hierarchy import linkage
from scipy.cluster.hierarchy import dendrogram
from scipy.spatial.distance import pdist
import matplotlib
from matplotlib import pyplot as plt
import numpy as np
from numpy import arange

# Create the figure and set it's size.
fig = plt.figure(figsize=(5,7))

# Create the first subplot in the figure. 
ax1 = plt.subplot2grid((3, 1), (0, 0), rowspan= 1, colspan=1)

# Set to your favorite colormap.
cm = matplotlib.cm.viridis

# Create array of random numbers.
X = np.random.random([6,300])

# Create a linkage object.
linkmat = linkage(X)

# Make a dendrogram from the linkage object.
dendrogram(linkmat)

# Use the x and y limits to set the aspect.
x0,x1 = ax1.get_xlim()
y0,y1 = ax1.get_ylim()
#ax1.set_aspect((x1-x0)/(y1-y0))


# Remove the ticks on the x-axis. 
plt.tick_params(axis='x', which='both', bottom='off', top='off', labelbottom='off')

# Create the second subplot.
ax2 = plt.subplot2grid((3, 1), (1, 0), rowspan= 2, colspan=1)

labels = ["a", "b", "c", "d", "e"]

plt.xticks(arange(0.5, 7.5, 1))

plt.gca().set_xticklabels(labels)

plt.pcolor(X.T)

x0,x1 = ax2.get_xlim()
y0,y1 = ax2.get_ylim()

#ax2.set_aspect((x1-x0)/(y1-y0))

# Insert the color scale
plt.colorbar()
cb = plt.colorbar(ax=ax1)
cb.ax.set_visible(False)

# Make the vertical distance between plots equal to zero 
plt.subplots_adjust(hspace=0)

# Show the plot
plt.show()
26. If \(t\) is less than or equal to zero, all nodes are colored
from scipy.cluster.hierarchy import linkage
from scipy.cluster.hierarchy import dendrogram
from scipy.spatial.distance import pdist
import matplotlib
from matplotlib import pyplot as plt
import numpy as np
from numpy import arange

# Create the figure and set it's size.
fig = plt.figure(figsize=(5,7))

# Create the first subplot in the figure. 
ax1 = plt.subplot2grid((3, 1), (0, 0), rowspan= 1, colspan=1)

# Set to your favorite colormap.
cm = matplotlib.cm.viridis

# Create array of random numbers.
X = np.random.random([6,300])

# Create a linkage object.
linkmat = linkage(X)

# Make a dendrogram from the linkage object.
dendrogram(linkmat)

# Use the x and y limits to set the aspect.
x0,x1 = ax1.get_xlim()
y0,y1 = ax1.get_ylim()
#ax1.set_aspect((x1-x0)/(y1-y0))


# Remove the ticks on the x-axis. 
plt.tick_params(axis='x', which='both', bottom='off', top='off', labelbottom='off')

# Create the second subplot.
ax2 = plt.subplot2grid((3, 1), (1, 0), rowspan= 2, colspan=1)

labels = ["a", "b", "c", "d", "e"]

plt.xticks(arange(0.5, 7.5, 1))

plt.gca().set_xticklabels(labels)

plt.pcolor(X.T)

x0,x1 = ax2.get_xlim()
y0,y1 = ax2.get_ylim()

#ax2.set_aspect((x1-x0)/(y1-y0))

# Insert the color scale
plt.colorbar()
cb = plt.colorbar(ax=ax1)
cb.ax.set_visible(False)

# Make the vertical distance between plots equal to zero 
plt.subplots_adjust(hspace=0)

# Show the plot
plt.show()
2 6. If
from scipy.cluster.hierarchy import linkage
from scipy.cluster.hierarchy import dendrogram
from scipy.spatial.distance import pdist
import matplotlib
from matplotlib import pyplot as plt
import numpy as np
from numpy import arange

# Create the figure and set it's size.
fig = plt.figure(figsize=(5,7))

# Create the first subplot in the figure. 
ax1 = plt.subplot2grid((3, 1), (0, 0), rowspan= 1, colspan=1)

# Set to your favorite colormap.
cm = matplotlib.cm.viridis

# Create array of random numbers.
X = np.random.random([6,300])

# Create a linkage object.
linkmat = linkage(X)

# Make a dendrogram from the linkage object.
dendrogram(linkmat)

# Use the x and y limits to set the aspect.
x0,x1 = ax1.get_xlim()
y0,y1 = ax1.get_ylim()
#ax1.set_aspect((x1-x0)/(y1-y0))


# Remove the ticks on the x-axis. 
plt.tick_params(axis='x', which='both', bottom='off', top='off', labelbottom='off')

# Create the second subplot.
ax2 = plt.subplot2grid((3, 1), (1, 0), rowspan= 2, colspan=1)

labels = ["a", "b", "c", "d", "e"]

plt.xticks(arange(0.5, 7.5, 1))

plt.gca().set_xticklabels(labels)

plt.pcolor(X.T)

x0,x1 = ax2.get_xlim()
y0,y1 = ax2.get_ylim()

#ax2.set_aspect((x1-x0)/(y1-y0))

# Insert the color scale
plt.colorbar()
cb = plt.colorbar(ax=ax1)
cb.ax.set_visible(False)

# Make the vertical distance between plots equal to zero 
plt.subplots_adjust(hspace=0)

# Show the plot
plt.show()
25 is None or ‘default’, corresponding with MATLAB(TM) behavior, the threshold is set to
from scipy.cluster.hierarchy import linkage
from scipy.cluster.hierarchy import dendrogram
from scipy.spatial.distance import pdist
import matplotlib
from matplotlib import pyplot as plt
import numpy as np
from numpy import arange

# Create the figure and set it's size.
fig = plt.figure(figsize=(5,7))

# Create the first subplot in the figure. 
ax1 = plt.subplot2grid((3, 1), (0, 0), rowspan= 1, colspan=1)

# Set to your favorite colormap.
cm = matplotlib.cm.viridis

# Create array of random numbers.
X = np.random.random([6,300])

# Create a linkage object.
linkmat = linkage(X)

# Make a dendrogram from the linkage object.
dendrogram(linkmat)

# Use the x and y limits to set the aspect.
x0,x1 = ax1.get_xlim()
y0,y1 = ax1.get_ylim()
#ax1.set_aspect((x1-x0)/(y1-y0))


# Remove the ticks on the x-axis. 
plt.tick_params(axis='x', which='both', bottom='off', top='off', labelbottom='off')

# Create the second subplot.
ax2 = plt.subplot2grid((3, 1), (1, 0), rowspan= 2, colspan=1)

labels = ["a", "b", "c", "d", "e"]

plt.xticks(arange(0.5, 7.5, 1))

plt.gca().set_xticklabels(labels)

plt.pcolor(X.T)

x0,x1 = ax2.get_xlim()
y0,y1 = ax2.get_ylim()

#ax2.set_aspect((x1-x0)/(y1-y0))

# Insert the color scale
plt.colorbar()
cb = plt.colorbar(ax=ax1)
cb.ax.set_visible(False)

# Make the vertical distance between plots equal to zero 
plt.subplots_adjust(hspace=0)

# Show the plot
plt.show()
29.get_leavesbool, tùy chọnbool, optional\(t\) be the
from scipy.cluster.hierarchy import linkage
from scipy.cluster.hierarchy import dendrogram
from scipy.spatial.distance import pdist
import matplotlib
from matplotlib import pyplot as plt
import numpy as np
from numpy import arange

# Create the figure and set it's size.
fig = plt.figure(figsize=(5,7))

# Create the first subplot in the figure. 
ax1 = plt.subplot2grid((3, 1), (0, 0), rowspan= 1, colspan=1)

# Set to your favorite colormap.
cm = matplotlib.cm.viridis

# Create array of random numbers.
X = np.random.random([6,300])

# Create a linkage object.
linkmat = linkage(X)

# Make a dendrogram from the linkage object.
dendrogram(linkmat)

# Use the x and y limits to set the aspect.
x0,x1 = ax1.get_xlim()
y0,y1 = ax1.get_ylim()
#ax1.set_aspect((x1-x0)/(y1-y0))


# Remove the ticks on the x-axis. 
plt.tick_params(axis='x', which='both', bottom='off', top='off', labelbottom='off')

# Create the second subplot.
ax2 = plt.subplot2grid((3, 1), (1, 0), rowspan= 2, colspan=1)

labels = ["a", "b", "c", "d", "e"]

plt.xticks(arange(0.5, 7.5, 1))

plt.gca().set_xticklabels(labels)

plt.pcolor(X.T)

x0,x1 = ax2.get_xlim()
y0,y1 = ax2.get_ylim()

#ax2.set_aspect((x1-x0)/(y1-y0))

# Insert the color scale
plt.colorbar()
cb = plt.colorbar(ax=ax1)
cb.ax.set_visible(False)

# Make the vertical distance between plots equal to zero 
plt.subplots_adjust(hspace=0)

# Show the plot
plt.show()
25. Colors all the descendent links below a cluster node \(k\) the same color if \(k\) is the first node below the cut threshold \(t\). All links connecting nodes with distances greater than or equal to the threshold are colored with de default matplotlib color
from scipy.cluster.hierarchy import linkage
from scipy.cluster.hierarchy import dendrogram
from scipy.spatial.distance import pdist
import matplotlib
from matplotlib import pyplot as plt
import numpy as np
from numpy import arange

# Create the figure and set it's size.
fig = plt.figure(figsize=(5,7))

# Create the first subplot in the figure. 
ax1 = plt.subplot2grid((3, 1), (0, 0), rowspan= 1, colspan=1)

# Set to your favorite colormap.
cm = matplotlib.cm.viridis

# Create array of random numbers.
X = np.random.random([6,300])

# Create a linkage object.
linkmat = linkage(X)

# Make a dendrogram from the linkage object.
dendrogram(linkmat)

# Use the x and y limits to set the aspect.
x0,x1 = ax1.get_xlim()
y0,y1 = ax1.get_ylim()
#ax1.set_aspect((x1-x0)/(y1-y0))


# Remove the ticks on the x-axis. 
plt.tick_params(axis='x', which='both', bottom='off', top='off', labelbottom='off')

# Create the second subplot.
ax2 = plt.subplot2grid((3, 1), (1, 0), rowspan= 2, colspan=1)

labels = ["a", "b", "c", "d", "e"]

plt.xticks(arange(0.5, 7.5, 1))

plt.gca().set_xticklabels(labels)

plt.pcolor(X.T)

x0,x1 = ax2.get_xlim()
y0,y1 = ax2.get_ylim()

#ax2.set_aspect((x1-x0)/(y1-y0))

# Insert the color scale
plt.colorbar()
cb = plt.colorbar(ax=ax1)
cb.ax.set_visible(False)

# Make the vertical distance between plots equal to zero 
plt.subplots_adjust(hspace=0)

# Show the plot
plt.show()
26. If \(t\) is less than or equal to zero, all nodes are colored
from scipy.cluster.hierarchy import linkage
from scipy.cluster.hierarchy import dendrogram
from scipy.spatial.distance import pdist
import matplotlib
from matplotlib import pyplot as plt
import numpy as np
from numpy import arange

# Create the figure and set it's size.
fig = plt.figure(figsize=(5,7))

# Create the first subplot in the figure. 
ax1 = plt.subplot2grid((3, 1), (0, 0), rowspan= 1, colspan=1)

# Set to your favorite colormap.
cm = matplotlib.cm.viridis

# Create array of random numbers.
X = np.random.random([6,300])

# Create a linkage object.
linkmat = linkage(X)

# Make a dendrogram from the linkage object.
dendrogram(linkmat)

# Use the x and y limits to set the aspect.
x0,x1 = ax1.get_xlim()
y0,y1 = ax1.get_ylim()
#ax1.set_aspect((x1-x0)/(y1-y0))


# Remove the ticks on the x-axis. 
plt.tick_params(axis='x', which='both', bottom='off', top='off', labelbottom='off')

# Create the second subplot.
ax2 = plt.subplot2grid((3, 1), (1, 0), rowspan= 2, colspan=1)

labels = ["a", "b", "c", "d", "e"]

plt.xticks(arange(0.5, 7.5, 1))

plt.gca().set_xticklabels(labels)

plt.pcolor(X.T)

x0,x1 = ax2.get_xlim()
y0,y1 = ax2.get_ylim()

#ax2.set_aspect((x1-x0)/(y1-y0))

# Insert the color scale
plt.colorbar()
cb = plt.colorbar(ax=ax1)
cb.ax.set_visible(False)

# Make the vertical distance between plots equal to zero 
plt.subplots_adjust(hspace=0)

# Show the plot
plt.show()
2 6. If
from scipy.cluster.hierarchy import linkage
from scipy.cluster.hierarchy import dendrogram
from scipy.spatial.distance import pdist
import matplotlib
from matplotlib import pyplot as plt
import numpy as np
from numpy import arange

# Create the figure and set it's size.
fig = plt.figure(figsize=(5,7))

# Create the first subplot in the figure. 
ax1 = plt.subplot2grid((3, 1), (0, 0), rowspan= 1, colspan=1)

# Set to your favorite colormap.
cm = matplotlib.cm.viridis

# Create array of random numbers.
X = np.random.random([6,300])

# Create a linkage object.
linkmat = linkage(X)

# Make a dendrogram from the linkage object.
dendrogram(linkmat)

# Use the x and y limits to set the aspect.
x0,x1 = ax1.get_xlim()
y0,y1 = ax1.get_ylim()
#ax1.set_aspect((x1-x0)/(y1-y0))


# Remove the ticks on the x-axis. 
plt.tick_params(axis='x', which='both', bottom='off', top='off', labelbottom='off')

# Create the second subplot.
ax2 = plt.subplot2grid((3, 1), (1, 0), rowspan= 2, colspan=1)

labels = ["a", "b", "c", "d", "e"]

plt.xticks(arange(0.5, 7.5, 1))

plt.gca().set_xticklabels(labels)

plt.pcolor(X.T)

x0,x1 = ax2.get_xlim()
y0,y1 = ax2.get_ylim()

#ax2.set_aspect((x1-x0)/(y1-y0))

# Insert the color scale
plt.colorbar()
cb = plt.colorbar(ax=ax1)
cb.ax.set_visible(False)

# Make the vertical distance between plots equal to zero 
plt.subplots_adjust(hspace=0)

# Show the plot
plt.show()
25 is None or ‘default’, corresponding with MATLAB(TM) behavior, the threshold is set to
from scipy.cluster.hierarchy import linkage
from scipy.cluster.hierarchy import dendrogram
from scipy.spatial.distance import pdist
import matplotlib
from matplotlib import pyplot as plt
import numpy as np
from numpy import arange

# Create the figure and set it's size.
fig = plt.figure(figsize=(5,7))

# Create the first subplot in the figure. 
ax1 = plt.subplot2grid((3, 1), (0, 0), rowspan= 1, colspan=1)

# Set to your favorite colormap.
cm = matplotlib.cm.viridis

# Create array of random numbers.
X = np.random.random([6,300])

# Create a linkage object.
linkmat = linkage(X)

# Make a dendrogram from the linkage object.
dendrogram(linkmat)

# Use the x and y limits to set the aspect.
x0,x1 = ax1.get_xlim()
y0,y1 = ax1.get_ylim()
#ax1.set_aspect((x1-x0)/(y1-y0))


# Remove the ticks on the x-axis. 
plt.tick_params(axis='x', which='both', bottom='off', top='off', labelbottom='off')

# Create the second subplot.
ax2 = plt.subplot2grid((3, 1), (1, 0), rowspan= 2, colspan=1)

labels = ["a", "b", "c", "d", "e"]

plt.xticks(arange(0.5, 7.5, 1))

plt.gca().set_xticklabels(labels)

plt.pcolor(X.T)

x0,x1 = ax2.get_xlim()
y0,y1 = ax2.get_ylim()

#ax2.set_aspect((x1-x0)/(y1-y0))

# Insert the color scale
plt.colorbar()
cb = plt.colorbar(ax=ax1)
cb.ax.set_visible(False)

# Make the vertical distance between plots equal to zero 
plt.subplots_adjust(hspace=0)

# Show the plot
plt.show()
29.get_leavesbool, tùy chọnbool, optional

Bao gồm một danh sách

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
70 trong từ điển kết quả. Đối với mỗi \ (i \),
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
71, nút cụm
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
72 xuất hiện ở vị trí
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
73 trong đường truyền từ trái sang phải của lá, trong đó \ (j \(j < 2n-1\) and \(i < n\).DirectionTr, tùy chọnstr, optional

Hướng để vẽ đồ họa, có thể là bất kỳ chuỗi nào sau đây:

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
74

Âm mưu gốc ở trên cùng và các liên kết hạ xuống âm mưu đi xuống dưới. (mặc định).

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
75

Âm mưu gốc ở phía dưới, và lô liên kết đi xuống đi lên.

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
76

Âm mưu gốc ở bên trái, và cốt truyện các liên kết đi xuống bên phải.

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
77

Âm mưu gốc ở bên phải, và lô liên kết đi xuống bên trái.

LabelSndarray, tùy chọnndarray, optionalndarray, optional

Theo mặc định,

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
78 không có gì vì vậy chỉ số của quan sát ban đầu được sử dụng để dán nhãn các nút lá. Mặt khác, đây là một chuỗi có kích thước \ (n \)-với
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
79. Giá trị
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
00 là văn bản đặt dưới nút lá \ (i \) chỉ khi nó tương ứng với quan sát ban đầu chứ không phải là cụm không phải là singleton.\(n\)-sized sequence, with
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
79. The
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
00 value is the text to put under the \(i\) th leaf node only if it corresponds to an original observation and not a non-singleton cluster.Count_Sortstr hoặc Bool, tùy chọnstr or bool, optional\(n\)-sized sequence, with
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
79. The
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
00 value is the text to put under the \(i\) th leaf node only if it corresponds to an original observation and not a non-singleton cluster.Count_Sortstr hoặc Bool, tùy chọnstr or bool, optional

Đối với mỗi nút N, thứ tự (trực quan, từ từ trái sang phải), hai liên kết hạ nguồn được vẽ được xác định bởi tham số này, có thể là bất kỳ giá trị nào sau đây:

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
01

Không có gì được thực hiện.

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
02 hoặc
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
03

Đứa trẻ có số lượng tối thiểu của các đối tượng gốc trong cụm của nó được vẽ đầu tiên.

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
04

Đứa trẻ có số lượng đối tượng gốc tối đa trong cụm của nó được vẽ trước.

Lưu ý,

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
05 và
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
06 đều không thể đúng.Disce_Sortstr hoặc Bool, Tùy chọnstr or bool, optionalDisce_Sortstr hoặc Bool, Tùy chọnstr or bool, optional

Đối với mỗi nút N, thứ tự (trực quan, từ từ trái sang phải), hai liên kết hạ nguồn được vẽ được xác định bởi tham số này, có thể là bất kỳ giá trị nào sau đây:

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
01

Không có gì được thực hiện.

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
02 hoặc
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
03

Đứa trẻ có số lượng tối thiểu của các đối tượng gốc trong cụm của nó được vẽ đầu tiên.

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
04

Đứa trẻ có số lượng đối tượng gốc tối đa trong cụm của nó được vẽ trước.

Lưu ý,

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
05 và
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
06 đều không thể đúng.Disce_Sortstr hoặc Bool, Tùy chọnstr or bool, optionalDisce_Sortstr hoặc Bool, Tùy chọnbool, optional

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
05 và
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
06 đều không thể đúng. Disce_Sortstr hoặc Bool, Tùy chọnbool, optional\(k>1\) original observation are labeled with the number of observations they contain in parentheses.

Đứa trẻ có khoảng cách tối thiểu giữa con cháu trực tiếp của nó được vẽ đầu tiên.\(k>1\) original observation are labeled with the number of observations they contain in parentheses.bool, optional

Đứa trẻ có khoảng cách tối đa giữa con cháu trực tiếp của nó được vẽ đầu tiên.bool, optional

Lưu ý show_leaf_countsbool, tùy chọnbool, optional

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
05 và
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
06 đều không thể đúng.show_leaf_countsbool, tùy chọnbool, optional

Khi đúng, các nút lá đại diện cho quan sát ban đầu \ (k> 1 \) được dán nhãn với số lượng quan sát mà chúng chứa trong ngoặc đơn.double, optional

No_plotbool, tùy chọndouble, optional

Khi đúng, kết xuất cuối cùng không được thực hiện. Điều này rất hữu ích nếu chỉ cần các cấu trúc dữ liệu được tính toán cho kết xuất hoặc nếu không có sẵn matplotlib.int, optional

NO_LabelSbool, tùy chọnint, optional

Khi đúng, không có nhãn nào xuất hiện bên cạnh các nút lá trong kết xuất của dendrogram.lambda or function, optional

Leaf_rotationDouble, tùy chọnlambda or function, optional\(k < 2n-1\). The function is expected to return a string with the label for the leaf.

Chỉ định góc (tính bằng độ) để xoay nhãn lá. Khi không xác định, vòng quay dựa trên số lượng nút trong dendrogram (mặc định là 0).\(k < 2n-1\). The function is expected to return a string with the label for the leaf.\(k < n\) correspond to original observations while indices \(k \geq n\) correspond to non-singleton clusters.

Chỉ định kích thước phông chữ (tính theo điểm) của nhãn lá. Khi không xác định, kích thước dựa trên số lượng nút trong dendrogram.

from scipy.cluster.hierarchy import linkage
from scipy.cluster.hierarchy import dendrogram
from scipy.spatial.distance import pdist
import matplotlib
from matplotlib import pyplot as plt
import numpy as np
from numpy import arange

# Create the figure and set it's size.
fig = plt.figure(figsize=(5,7))

# Create the first subplot in the figure. 
ax1 = plt.subplot2grid((3, 1), (0, 0), rowspan= 1, colspan=1)

# Set to your favorite colormap.
cm = matplotlib.cm.viridis

# Create array of random numbers.
X = np.random.random([6,300])

# Create a linkage object.
linkmat = linkage(X)

# Make a dendrogram from the linkage object.
dendrogram(linkmat)

# Use the x and y limits to set the aspect.
x0,x1 = ax1.get_xlim()
y0,y1 = ax1.get_ylim()
#ax1.set_aspect((x1-x0)/(y1-y0))


# Remove the ticks on the x-axis. 
plt.tick_params(axis='x', which='both', bottom='off', top='off', labelbottom='off')

# Create the second subplot.
ax2 = plt.subplot2grid((3, 1), (1, 0), rowspan= 2, colspan=1)

labels = ["a", "b", "c", "d", "e"]

plt.xticks(arange(0.5, 7.5, 1))

plt.gca().set_xticklabels(labels)

plt.pcolor(X.T)

x0,x1 = ax2.get_xlim()
y0,y1 = ax2.get_ylim()

#ax2.set_aspect((x1-x0)/(y1-y0))

# Insert the color scale
plt.colorbar()
cb = plt.colorbar(ax=ax1)
cb.ax.set_visible(False)

# Make the vertical distance between plots equal to zero 
plt.subplots_adjust(hspace=0)

# Show the plot
plt.show()
2Leaf_label_funclambda hoặc chức năng, tùy chọnbool, optionalLeaf_label_funclambda hoặc chức năng, tùy chọnbool, optional

Khi

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
83 là một hàm có thể gọi được, cho mỗi lá có chỉ số cụm \ (k Chỉ số \ (k callable, optional

Ví dụ, để dán nhãn singletons với ID nút và không phải là Singletons với ID, đếm và hệ số không nhất quán của họ, chỉ cần làm:

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
7

show_contractedBool, tùy chọn

Khi đúng, độ cao của các nút không phải là singleton được ký kết thành một nút lá được vẽ như các chữ thập dọc theo liên kết kết nối nút lá đó. Điều này thực sự chỉ hữu ích khi sử dụng cắt ngắn (xem tham số
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
2).matplotlib Axes instance, optional
matplotlib Axes instance, optional

link_color_funccallable, tùy chọn

Nếu được đưa ra, Link_Color_Function được gọi với mỗi ID không phải là Singleton tương ứng với từng liên kết hình chữ U mà nó sẽ vẽ. Hàm dự kiến ​​sẽ trả về màu để sơn liên kết, được mã hóa dưới dạng mã chuỗi màu matplotlib. Ví dụ:str, optionalstr, optional

Màu sắc các liên kết trực tiếp bên dưới mỗi nút không singleton chưa được nhấn

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
85 bằng
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
86.Ví dụ Axmatplotlib Axes, Tùy chọnRdictRdict

Nếu không có và no_plot là không đúng, dendrogram sẽ được vẽ trên các trục hiện tại. Mặt khác, nếu NO_PLOT không đúng, dendrogram sẽ được vẽ trên thể hiện

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
87 đã cho. Điều này có thể hữu ích nếu dendrogram là một phần của một con số phức tạp hơn.
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
89

TRÊN_THRESHOLD_COLORSTR, Tùy chọn

Chuỗi màu matplotlib này đặt màu của các liên kết phía trên color_threshold. Mặc định là
from scipy.cluster.hierarchy import linkage
from scipy.cluster.hierarchy import dendrogram
from scipy.spatial.distance import pdist
import matplotlib
from matplotlib import pyplot as plt
import numpy as np
from numpy import arange

# Create the figure and set it's size.
fig = plt.figure(figsize=(5,7))

# Create the first subplot in the figure. 
ax1 = plt.subplot2grid((3, 1), (0, 0), rowspan= 1, colspan=1)

# Set to your favorite colormap.
cm = matplotlib.cm.viridis

# Create array of random numbers.
X = np.random.random([6,300])

# Create a linkage object.
linkmat = linkage(X)

# Make a dendrogram from the linkage object.
dendrogram(linkmat)

# Use the x and y limits to set the aspect.
x0,x1 = ax1.get_xlim()
y0,y1 = ax1.get_ylim()
#ax1.set_aspect((x1-x0)/(y1-y0))


# Remove the ticks on the x-axis. 
plt.tick_params(axis='x', which='both', bottom='off', top='off', labelbottom='off')

# Create the second subplot.
ax2 = plt.subplot2grid((3, 1), (1, 0), rowspan= 2, colspan=1)

labels = ["a", "b", "c", "d", "e"]

plt.xticks(arange(0.5, 7.5, 1))

plt.gca().set_xticklabels(labels)

plt.pcolor(X.T)

x0,x1 = ax2.get_xlim()
y0,y1 = ax2.get_ylim()

#ax2.set_aspect((x1-x0)/(y1-y0))

# Insert the color scale
plt.colorbar()
cb = plt.colorbar(ax=ax1)
cb.ax.set_visible(False)

# Make the vertical distance between plots equal to zero 
plt.subplots_adjust(hspace=0)

# Show the plot
plt.show()
26.

Trả về rdict

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
10

Một từ điển của các cấu trúc dữ liệu được tính toán để hiển thị từ ngữ. Nó có các khóa sau:

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
11

Một danh sách các tên màu. Phần tử K hèth đại diện cho màu của liên kết K K.\(j < 2n-1\) and \(i < n\). If \(j < 2n-1\) and \(i < n\). If

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
72 is less than
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
16, the
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
73-th leaf node corresponds to an original observation. Otherwise, it corresponds to a non-singleton cluster.
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
18
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
80 và
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
81

Mỗi người trong số họ là một danh sách các danh sách. Đặt

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
82 trong đó
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
83 và
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
84 trong đó
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
85, thì liên kết Kiênth được vẽ là
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
86 -
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
87 -
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
88 -
from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
89.

Một danh sách các nhãn tương ứng với các nút lá.

Ví dụ

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
0

Một ví dụ rất cơ bản:

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
8

Bây giờ, sơ đồ trong các trục đã cho, cải thiện bảng màu và sử dụng cả hai hướng dọc và ngang:

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[2, ])
b = np.random.multivariate_normal([0, 10], [[3, 1], [1, 4]], size=[3, ])
X = np.concatenate((a, b), )
Z = linkage(X)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
dendrogram(Z, ax=ax)
plt.show()
8

Làm thế nào để bạn tạo ra một dendrogram trong Python?

Dendrograms trong Python...

Dendrogram cơ bản. Một dendrogram là một sơ đồ đại diện cho một cây. Nhà máy hình có tên created_dendrogram thực hiện phân cụm phân cấp trên dữ liệu và biểu thị cây kết quả. ....

Đặt ngưỡng màu ..

Đặt định hướng và thêm nhãn ..

Vẽ một dendrogram với một bản đồ nhiệt. Xem thêm Bản demo Bio Dash ..

Làm thế nào để bạn phân tích một dendrogram?

Có hai cách để giải thích một dendrogram: về mặt các nhóm quy mô lớn hoặc về sự tương đồng giữa các khối cá nhân.Để xác định các nhóm quy mô lớn, chúng tôi bắt đầu đọc từ trên xuống, tìm các điểm nhánh ở mức cao trong cấu trúc.in terms of large-scale groups or in terms of similarities among individual chunks. To identify large-scale groups, we start reading from the top down, finding the branch points that are at high levels in the structure.in terms of large-scale groups or in terms of similarities among individual chunks. To identify large-scale groups, we start reading from the top down, finding the branch points that are at high levels in the structure.

Bạn cắt một dendrogram ở đâu?

Cách tối ưu để cắt một dendrogram mục tiêu của chúng tôi, một cách ngắn gọn, là cắt dendrogram thành các con trừ K để một số mất được chọn đạt được mức tối thiểu.k disjoint subtrees such that some chosen loss achieves the minimum.k disjoint subtrees such that some chosen loss achieves the minimum.

Dendrogram trong phân tích cụm là gì?

Một dendrogram là một sơ đồ cho thấy mối quan hệ phân cấp giữa các đối tượng.Nó thường được tạo ra như một đầu ra từ phân cụm phân cấp.Việc sử dụng chính của dendrogram là tìm ra cách tốt nhất để phân bổ các đối tượng cho các cụm.