我正在使用matplotlib绘制层次聚类,

import numpy as np

from scipy.cluster.hierarchy import dendrogram

def plot_dendrogram(model, **kwargs):

    # Children of hierarchical clustering
    children = model.children_

    # Distances between each pair of children
    # Since we don't have this information, we can use a uniform one for plotting
    distance = np.arange(children.shape[0])



    # The number of observations contained in each cluster level
    no_of_observations = np.arange(2, children.shape[0]+2)

    # Create linkage matrix and then plot the dendrogram
    linkage_matrix = np.column_stack([children, distance, no_of_observations]).astype(float)

    # Plot the corresponding dendrogram
    dendrogram(linkage_matrix, **kwargs)

plt.figure(figsize=(100,100))
plt.title('Hierarchical Clustering Dendrogram')
plot_dendrogram(clustering, labels=liste_tags)
plt.show()


我可以可视化分层聚类,但是该图的质量和分辨率都不好。特别是,当我保存图解并尝试放大以查看标签时。

我得到此图像:python - Matplotlib缩放时绘制不良分辨率-LMLPHP

最佳答案

MatPlotLib Figure对象具有一个dpi参数。只需设置plt.figure(figsize=(100,100), dpi=300)之类的内容即可。

10-07 21:46