【问题标题】:Matplotlib plot bad resolution when zoomingMatplotlib 在缩放时绘制错误的分辨率
【发布时间】:2019-10-13 23:21:13
【问题描述】:

我正在使用 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 plot hierarchical-clustering


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2012-02-25
      • 2017-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-27
      • 1970-01-01
      相关资源
      最近更新 更多