2014-03-31 61 views
4

我正在使用SciPy製作一個大型樹狀圖,並且在得到的樹狀圖中,線條粗細使得難以看清細節。我想減小線條粗細,以便更容易看到和更多MatLab。有什麼建議麼?使用SciPy樹狀圖,我可以更改線寬嗎?

我做:

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') 

而且越來越像this結果。

回答

5

在調用dendrogram之前設置默認線寬。例如:

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') 

有關更多信息,請參見Customizing matplotlib

+0

可以這樣做,而不是從import pyplot中單獨導入matplotlib? –

+0

寬度單位是多少?它是像素還是點? – Sigur

2

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') 

有關詳細信息,請參閱Matplotlib configuration API

相關問題