Matplotlib缩放时绘制不良分辨率

时间:2019-05-28 12:14:36

标签: python matplotlib plot hierarchical-clustering

我正在使用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()

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

我得到这张图片:enter image description here

1 个答案:

答案 0 :(得分:0)

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