【发布时间】:2019-10-01 17:14:21
【问题描述】:
我似乎无法使用 Python/PyCharm 中的 dtaidistance 包更改输出绘图大小。 model.plot 函数中似乎没有“figsize”参数或类似参数,并且如下所述以 SciPy 样式包装整个图会导致空图 [代码改编自 https://pydigger.com/pypi/dtaidistance]:
import matplotlib.pyplot as plt
from dtaidistance import dtw, clustering
import numpy as np
# demo data matrix:
series = np.matrix([
[0., 0, 1, 2, 1, 0, 1, 0, 0],
[0., 1, 2, 0, 0, 0, 0, 0, 0],
[1., 2, 0, 0, 0, 0, 0, 1, 1],
[0., 0, 1, 2, 1, 0, 1, 0, 0],
[0., 1, 2, 0, 0, 0, 0, 0, 0],
[1., 2, 0, 0, 0, 0, 0, 1, 1]])
# Custom Hierarchical clustering
model1 = clustering.Hierarchical(dtw.distance_matrix_fast, {})
# Augment Hierarchical object to keep track of the full tree
model2 = clustering.HierarchicalTree(model1)
# Fit Model:
cluster_idx = model2.fit(series=series)
# create plot:
fig = plt.figure(figsize=(14, 10))
tree = model2.plot("mytree.png")
plt.show()
在当前状态下,绘图保存为 mytree.png,但分辨率非常低。这个低分辨率图可以通过
显示import matplotlib.image as mpimg
img = mpimg.imread("mytree.png")
imgplot = plt.imshow(img)
plt.show()
但我需要比提供的分辨率高得多的分辨率...
【问题讨论】:
标签: python plot hierarchical-clustering