本文整理汇总了Python中plotly.tools.FigureFactory.create_dendrogram方法的典型用法代码示例。如果您正苦于以下问题:Python FigureFactory.create_dendrogram方法的具体用法?Python FigureFactory.create_dendrogram怎么用?Python FigureFactory.create_dendrogram使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plotly.tools.FigureFactory
的用法示例。
在下文中一共展示了FigureFactory.create_dendrogram方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: glob
# 需要导入模块: from plotly.tools import FigureFactory [as 别名]
# 或者: from plotly.tools.FigureFactory import create_dendrogram [as 别名]
base = '/home/vanessa/Documents/Work/SINGULARITY'
results_folder = "%s/results" %(base)
results_files = glob("%s/*.tsv" %(results_folder))
# From https://plot.ly/python/dendrogram/, thanks plotly! :)
# Load each data file and make html heatmap
for results_file in results_files:
data = pandas.read_csv(results_file,index_col=0,sep="\t")
lookup = {x:x.split("-")[0] for x in data.index.tolist()}
labels = [lookup[x] for x in data.index.tolist()]
# Initialize figure by creating upper dendrogram
figure = FF.create_dendrogram(data, orientation='bottom', labels=labels)
for i in range(len(figure['data'])):
figure['data'][i]['yaxis'] = 'y2'
# Create Side Dendrogram
dendro_side = FF.create_dendrogram(data, orientation='right')
for i in range(len(dendro_side['data'])):
dendro_side['data'][i]['xaxis'] = 'x2'
# Add Side Dendrogram Data to Figure
figure['data'].extend(dendro_side['data'])
# Create Heatmap
dendro_leaves = dendro_side['layout']['yaxis']['ticktext']
dendro_leaves = list(map(int, dendro_leaves))
data_dist = pdist(data)
示例2: __init__
# 需要导入模块: from plotly.tools import FigureFactory [as 别名]
# 或者: from plotly.tools.FigureFactory import create_dendrogram [as 别名]
def __init__(self, dendrogram):
x = np.array(dendrogram)
fig = FigureFactory.create_dendrogram(x, orientation='left')
fig['layout'].update({'width':800, 'height':800})
plotly.offline.plot(fig, filename='dendrogram_with_labels')
示例3: generate_dendrogram
# 需要导入模块: from plotly.tools import FigureFactory [as 别名]
# 或者: from plotly.tools.FigureFactory import create_dendrogram [as 别名]
def generate_dendrogram(self):
labels = self.names
x = np.array(self.data.distance_matrix)
# Initialize figure by creating upper dendrogram
figure = FF.create_dendrogram(x, orientation='bottom', labels=labels)
for i in range(len(figure['data'])):
figure['data'][i]['yaxis'] = 'y2'
# Create Side Dendrogram
dendro_side = FF.create_dendrogram(x, orientation='right')
for i in range(len(dendro_side['data'])):
dendro_side['data'][i]['xaxis'] = 'x2'
# Add Side Dendrogram Data to Figure
figure['data'].extend(dendro_side['data'])
# Create Heatmap
dendro_leaves = dendro_side['layout']['yaxis']['ticktext']
dendro_leaves = list(map(int, dendro_leaves))
data_dist = pdist(x)
heat_data = squareform(data_dist)
heat_data = heat_data[dendro_leaves,:]
heat_data = heat_data[:,dendro_leaves]
heatmap = go.Data([
go.Heatmap(
x = dendro_leaves,
y = dendro_leaves,
z = heat_data,
colorscale = 'YIGnBu'
)
])
heatmap[0]['x'] = figure['layout']['xaxis']['tickvals']
heatmap[0]['y'] = dendro_side['layout']['yaxis']['tickvals']
# Add Heatmap Data to Figure
figure['data'].extend(go.Data(heatmap))
# Edit Layout
figure['layout'].update({'width':1600, 'height':1600,
'showlegend':False, 'hovermode': 'closest',
'margin': { 'b': 400 }
})
# Edit xaxis
figure['layout']['xaxis'].update({'domain': [.15, 1],
'mirror': False,
'showgrid': False,
'showline': False,
'zeroline': False,
'ticks':""})
# Edit xaxis2
figure['layout'].update({'xaxis2': {'domain': [0, .15],
'mirror': False,
'showgrid': False,
'showline': False,
'zeroline': False,
'showticklabels': False,
'ticks':""}})
# Edit yaxis
figure['layout']['yaxis'].update({'domain': [0, .85],
'mirror': False,
'showgrid': False,
'showline': False,
'zeroline': False,
'showticklabels': False,
'ticks': ""})
# Edit yaxis2
figure['layout'].update({'yaxis2':{'domain':[.825, .975],
'mirror': False,
'showgrid': False,
'showline': False,
'zeroline': False,
'showticklabels': False,
'ticks':""}})
# Plot!
plotly.offline.plot(figure, filename='output/dendrogram_with_heatmap.html')
示例4: generate_dendrogram_plotly
# 需要导入模块: from plotly.tools import FigureFactory [as 别名]
# 或者: from plotly.tools.FigureFactory import create_dendrogram [as 别名]
def generate_dendrogram_plotly(json_data, tree_filename="infomap/output/"+"author_graph.tree"):
author_graph = nx.Graph()
dist_queue = linkage_matrix = pair_queue = list()
print("Reading author UIDs from JSON file...")
with open('author_uid_map.json', 'r') as map_file:
author_uid_map = json.load(map_file)
map_file.close()
# Use node_limit to limit the number of authors
# node_limit = len(author_uid_map)
node_limit = 100
# buffer_queue = numpy.ndarray((node_limit,2), dtype=float)
#
# print("Adding nodes to author's graph...")
# for msg_id, message in json_data.items():
# if message['Cc'] is None:
# addr_list = message['To']
# else:
# addr_list = message['To'] | message['Cc']
# for to_address in addr_list:
# if author_graph.has_edge(message['From'], to_address):
# author_graph[message['From']][to_address]['weight'] *= \
# author_graph[message['From']][to_address]['weight'] / (author_graph[message['From']][to_address]['weight'] + 1)
# else:
# author_graph.add_edge(message['From'], to_address, weight=1)
# shortest_paths = nx.single_source_shortest_path_length(author_graph, '[email protected]')
#
# print("Parsing", tree_filename + "...")
# with open(tree_filename, 'r') as tree_file:
# for line in tree_file:
# if not line or line[0] == '#':
# continue
# line = line.split()
# author_uid = author_uid_map[line[2][1:-1]]
# if author_uid < node_limit:
# if line[2][1:-1] in shortest_paths.keys():
# buffer_queue[author_uid][0] = shortest_paths[line[2][1:-1]]
# else:
# buffer_queue[author_uid][0] = 1000.0
# buffer_queue[author_uid][1] = float(line[1])
# tree_file.close()
dist_matrix = numpy.ndarray((node_limit, node_limit), dtype=float)
for msg_id, message in json_data.items():
if author_uid_map[message['From']] < node_limit:
if message['Cc'] is None:
addr_list = message['To']
else:
addr_list = message['To'] | message['Cc']
for to_address in addr_list:
if author_uid_map[to_address] < node_limit:
if author_graph.has_edge(message['From'], to_address):
author_graph[message['From']][to_address]['weight'] *= \
author_graph[message['From']][to_address]['weight'] / (
author_graph[message['From']][to_address]['weight'] + 1)
else:
author_graph.add_edge(message['From'], to_address, weight=1)
shortest_paths = nx.all_pairs_shortest_path_length(author_graph)
print("Nodes added to the author's graph.")
for i1 in author_graph.nodes():
for i2 in author_graph.nodes():
if i2 in shortest_paths[i1]:
dist_matrix[author_uid_map[i1]][author_uid_map[i2]] = shortest_paths[i1][i2]
else:
dist_matrix[author_uid_map[i1]][author_uid_map[i2]] = 100
print("Drawing the dendrogram...")
# linkage_matrix = linkage(buffer_queue, 'single')
# dendro = FF.create_dendrogram(linkage_matrix)
dendro = FF.create_dendrogram(dist_matrix)
dendro['layout'].update({'width': 1200, 'height': 800})
plotly.offline.plot(dendro, filename='dendrogram_infomaps.html')