plot.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:fri 作者: lpfann 项目源码 文件源码
def plot_dendrogram_and_intervals(intervals,linkage,threshold=0.55,ticklabels=None):
    z = linkage
    fig = plt.figure(figsize=(13, 6))

    # Top dendrogram plot
    ax2 = fig.add_subplot(211)
    d = dendrogram(
        z,
        color_threshold=threshold,
        leaf_rotation=0.,  # rotates the x axis labels
        leaf_font_size=12.,  # font size for the x axis labels
        ax=ax2
    )
    # Get index determined through linkage method and dendrogram
    rearranged_index = d['leaves']
    ranges = intervals[rearranged_index]

    ax = fig.add_subplot(212)
    N = len(ranges)
    if  ticklabels is None:
        ticks = np.array(rearranged_index)
        ticks +=1 # Index starting at 1
    else:
        ticks = list(ticklabels[rearranged_index])

    ind = np.arange(N)+1
    width = 0.6
    upper_vals = ranges[:,1]
    lower_vals = ranges[:,0]
    bars = ax.bar(ind, upper_vals - lower_vals, width,bottom=lower_vals,tick_label=ticks,align="center" ,linewidth=1.3)

    plt.ylabel('relevance',fontsize=19)
    plt.xlabel('feature',fontsize=19)
    plt.xticks(ind,ticks, rotation='vertical')
    ax.margins(x=0)
    ax2.set_xticks([])
    ax2.margins(x=0)
    plt.tight_layout()
    #plt.subplots_adjust(wspace=0, hspace=0)

    return fig
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号