Can I change the line width with the SciPy dendrogram?

I make a big dendrogram using SciPy, and as a result of creating a dendrogram, the line thickness makes it difficult to see the details. I want to reduce the thickness of the line to make it easier to see, and more like MatLab. Any suggestions?

I do:

import scipy.cluster.hierarchy as hicl
from pylab import savefig

distance = #distance matrix

links = hicl.linkage(distance,method='average')
pden = hicl.dendrogram(links,color_threshold=optcutoff[0], ...
       count_sort=True,no_labels=True)
savefig('foo.pdf')

And we get a result like this .

+4
source share
2 answers

Set the default line width before calling dendrogram. For example:

import scipy.cluster.hierarchy as hicl
from pylab import savefig
import matplotlib


# Override the default linewidth.
matplotlib.rcParams['lines.linewidth'] = 0.5

distance = #distance matrix

links = hicl.linkage(distance,method='average')
pden = hicl.dendrogram(links,color_threshold=optcutoff[0], ...
       count_sort=True,no_labels=True)
savefig('foo.pdf')

See Configuring matplotlib for details .

+5
source

Matplotlib , :

import matplotlib.pyplot as plt
from scipy.cluster import hierarchy

distance = #distance matrix
links = hierarchy.linkage(distance, method='average')

# Temporarily override the default line width:
with plt.rc_context({'lines.linewidth': 0.5}):
    pden = hierarchy.dendrogram(links, color_threshold=optcutoff[0], ...
                                count_sort=True, no_labels=True)
# linewidth is back to its default here...!
plt.savefig('foo.pdf')

. API Matplotlib.

+2

Source: https://habr.com/ru/post/1534337/


All Articles