def show_spec_in_graph(graph, vertex, spec, pos, weight, file_name): dist = 1.0 - squareform(pdist(spec.T, 'cosine')) plt.figure() plt.stem(dist[vertex, :], markerfmt=' ') rim = graph.new_vertex_property('vector<double>') rim.set_2d_array(np.array([0, 0, 0, 1])) rim[graph.vertex(vertex)] = [0.8941176471, 0.1019607843, 0.1098039216, 1] rim_width = graph.new_vertex_property('float', vals=0.5) rim_width.a[vertex] = 2 shape = graph.new_vertex_property('int', vals=0) shape[graph.vertex(vertex)] = 2 size = graph.new_vertex_property('double', vals=10) size.a[vertex] = 15 correlation = graph.new_vertex_property('double', vals=2) correlation.a = dist[vertex, :] vorder = graph.new_vertex_property('int', vals=0) vorder.a[vertex] = 1 palette = sns.cubehelix_palette(256) cmap = colors.ListedColormap(palette) gt_draw.graph_draw(graph, pos=pos, vertex_color=rim, vorder=vorder, vertex_pen_width=rim_width, vertex_shape=shape, vertex_fill_color=correlation, vcmap=cmap, vertex_size=size, edge_color=[0, 0, 0, 0.7], edge_pen_width=weight, output=file_name + '.png', output_size=(1200, 1200)) plt.figure() utils.plot_colorbar(cmap, np.arange(0, 1.01, 0.2), file_name)
def plot(graph, weights, pos, station_values, name): palette = sns.color_palette('RdBu', n_colors=256) cmap = colors.ListedColormap(palette[::-1]) weights = weights.copy() weights.a -= np.min(weights.a) weights.a *= 2 / np.max(weights.a) weights.a += 0.2 gt_draw.graph_draw(graph, pos=pos, vertex_color=[0, 0, 0, 0.5], vertex_fill_color=station_values, vcmap=cmap, vertex_size=5, edge_color=[0, 0, 0, 0.7], edge_pen_width=weights, output=name + '_temp.svg') gt_draw.graph_draw(graph, pos=pos, vertex_color=[0, 0, 0, 0.5], vertex_fill_color=station_values, vcmap=cmap, vertex_size=10, edge_color=[0, 0, 0, 0.7], edge_pen_width=weights, output=name + '_temp.png', output_size=(1200, 1200)) min_val = np.min(station_values.a) max_val = np.max(station_values.a) step = (max_val - min_val) / 5 labels = np.array(['{0:.2f}'.format(x) for x in np.arange(min_val, max_val, step)]) plt.figure() utils.plot_colorbar(cmap, labels, name)