def plot_distance_distribution(graph): count = {} for n in list(graph): tmp_dict = nx.shortest_path_length(graph, source=n) tmp_res = 0 for j in list(graph): if n != j: try: tmp_res += tmp_dict[j] except KeyError: continue count[n] = tmp_res / (len(list(graph)) - 1) counts = {} for n in count: if n not in counts: counts[n] = 0 counts[n] += 1 x, y = log_binning(count, 150) trace = go.Scatter(x=np.array(y), y=np.array(x), mode='markers', line=dict(color=('rgb(205, 12, 24)'))) layout = dict(title="Distance Distribution", xaxis=dict(title='Average distance', type='log'), yaxis=dict(title='Count', type='log')) plot_data = [trace] fig = go.Figure(data=plot_data, layout=layout) image.save_as(fig, filename=IMG_PATH + 'distance_distribution.jpeg')
def sensitivity_analysis(si, names, year, num=0): trace1 = go.Bar(x=names[num:], y=si["S1"][num:], name='S1', error_y=dict(type='data', array=si['S1_conf'][num:], visible=True)) trace2 = go.Bar(x=names[num:], y=si['ST'][num:], name='Total', error_y=dict(type='data', array=si['ST_conf'][num:], visible=True)) data = [trace1, trace2] layout = go.Layout(barmode='group', title=''.join(['Sensitivity analysis for ', str(year)])) if num: title = '_groups_coeffs_' else: title = '_full_coeffs_' fig = go.Figure(data=data, layout=layout) image.save_as(fig, filename=''.join([path_to_figure, title, str(year), '.jpeg']))
def plot_kernel_density(sample, y, name): x = np.array(sample) y = np.array(y) trace = go.Scatter(x=x, y=y) data = [trace] fig = go.Figure(data=data) image.save_as(fig, filename=path_to_figure + name)
def plot_speedup(in_files): data = _parse_in(in_files) data['total_time'] = pd.to_datetime(data['total_time']) seconds = 1000000 * data['total_time'].dt.second minutes = 60000000 * data['total_time'].dt.minute data['time'] = data['total_time'].dt.microsecond + seconds + minutes ls_names = list(data['algorithm_name'].unique()) print(ls_names) for i in ls_names: seconds = [] arr_tmp = data.query('algorithm_name == @i').copy() arr_tmp = arr_tmp.groupby('cpu_count')['time'].mean() print(arr_tmp) cpu = list(arr_tmp.index.values) for j in cpu: seconds += [arr_tmp[j]] print(cpu, seconds) seconds_sequential = seconds[0] for k in range(len(seconds)): seconds[k] = seconds_sequential / seconds[k] print(cpu, seconds) trace = go.Scatter(x=np.array(cpu), y=np.array(seconds), mode='lines+markers', line=dict(color=('rgb(205, 12, 24)'))) layout = dict(title=i, xaxis=dict(title='Cpu count'), yaxis=dict(title='Speedup')) plot_data = [trace] fig = go.Figure(data=plot_data, layout=layout) image.save_as(fig, filename=path_to_figure + i + '.jpeg')
def plot_avg_binned_degree_connectivity(connect): items = sorted(connect.items()) x, y = log_binning(connect, 60) trace = go.Scatter(x=np.array(x), y=np.array(y), mode='markers', line=dict(color=('rgb(205, 12, 24)'))) layout = dict(title="Assortativity in", xaxis=dict(title='k'), yaxis=dict(title='$<k_{nn}>$')) plot_data = [trace] fig = go.Figure(data=plot_data, layout=layout) image.save_as(fig, filename=IMG_PATH + 'assortativity_in_binned.jpeg')
def plot_res(temp, magnetization): trace = go.Scatter(x=temp, y=[abs(mag) for mag in magnetization], mode='lines+markers') layout = dict( title='Magnetization dynamics with different fractions of conformists', xaxis=dict(title='P_c'), yaxis=dict(title='M'), ) data = [trace] fig = go.Figure(data=data, layout=layout) plot(fig, image_filename="test.png") image.save_as(fig, filename='conf_magnetization' + '.jpeg')
def plot_distributions(train, test, title='Rating distribution in Amazon dataset'): x = ['1', '2', '3', '4', '5'] trace1 = go.Bar(x=x, y=train, name='Train') trace2 = go.Bar(x=x, y=test, name='Test') data = [trace1, trace2] layout = go.Layout(title=title, barmode='group', yaxis=dict(title='# of reviews'), xaxis=dict(title='Rating')) fig = go.Figure(data=data, layout=layout) image.save_as(fig, filename=''.join([FIG_DIR, 'rating_distribution', '.jpeg']))
def coeff_visualization(data, years): year_categories = [i for i in range(len(data[0]))] trace = [] for i in range(len(data)): trace += [ go.Scatter(x=year_categories, y=data[i], name=years[i], mode='lines+markers') ] layout = dict( title='Checking validity of coeffs', xaxis=dict(title='Transition to age group'), yaxis=dict(title='Value'), ) fig = go.Figure(data=trace, layout=layout) image.save_as(fig, filename=path_to_figure + 'check_coeffs.jpeg')
def profile_compare_years(data, years, type, title): traces = [] for year in years: y = [ y * 1000 for y in data[data['date'] == year][group].values.tolist()[0] ] traces += [go.Scatter(x=group, y=y, mode='lines+markers', name=year)] years = [str(year) for year in years] layout = dict( title='Demographic profile prediction for Russia in ' + ', '.join(years) + ' (' + type + ')', xaxis=dict(title='Age group'), yaxis=dict(title='Amount of people'), ) fig = go.Figure(data=traces, layout=layout) image.save_as(fig, filename=path_to_figure + title + '.jpeg')
def show_profile(data, year, type, title): y = [ y * 1000 for y in data[data['date'] == year][group].values.tolist()[0] ] trace = go.Scatter(x=group, y=y, mode='lines+markers', name='title', line=dict(color=('rgb(205, 12, 24)'))) layout = dict( title='Demographic profile prediction for Russia in ' + str(year) + ' (' + type + ')', xaxis=dict(title='Age group'), yaxis=dict(title='Amount of people'), ) data = [trace] fig = go.Figure(data=data, layout=layout) image.save_as(fig, filename=path_to_figure + title + '.jpeg')
def profiles_m_f(fem_data, male_data, year, title): y = [ y * 1000 for y in fem_data[fem_data['date'] == year][group].values.tolist()[0] ] trace1 = go.Scatter(x=group, y=y, mode='lines+markers', name='female') y = [ y * 1000 for y in male_data[male_data['date'] == year][group].values.tolist()[0] ] trace2 = go.Scatter(x=group, y=y, mode='lines+markers', name='male') layout = dict( title='Demographic profile prediction for Russia in ' + str(year), xaxis=dict(title='Age group'), yaxis=dict(title='Amount of people'), ) data = [trace1, trace2] fig = go.Figure(data=data, layout=layout) image.save_as(fig, filename=path_to_figure + title + '.jpeg')
def plot_binned_clustering_coeffs(data): values = data['clustering'] values = [float(i) for i in values] counts = {} for n in values: if n not in counts: counts[n] = 0 counts[n] += 1 x, y = log_binning(counts, 60) trace = go.Scatter(x=np.array(x), y=np.array(y), mode='markers', line=dict(color=('rgb(205, 12, 24)'))) layout = dict(title="Clustering Distribution", xaxis=dict(title='Clustering Coefficient', type='log'), yaxis=dict(title='Count', type='log')) plot_data = [trace] fig = go.Figure(data=plot_data, layout=layout) image.save_as(fig, filename=IMG_PATH + 'clustering_binned.jpeg')
def plot_binned_betweeness_centrality(data): values = data['betweenesscentrality'] values = [float(i) for i in values] counts = {} for n in values: if n not in counts: counts[n] = 0 counts[n] += 1 x, y = log_binning(counts, 60) trace = go.Scatter(x=np.array(x), y=np.array(y), mode='markers', line=dict(color=('rgb(205, 12, 24)'))) layout = dict(title="Beetweeness Distribution", xaxis=dict(title='Betweenness centrality', type='log'), yaxis=dict(title='Count', type='log')) plot_data = [trace] fig = go.Figure(data=plot_data, layout=layout) image.save_as(fig, filename=IMG_PATH + 'betweenesscentrality_binned2.jpeg')
def uncertainty_plot(min_population, max_population, average_population, simulated_years): trace1 = go.Scatter(y=min_population, x=simulated_years, mode='lines', line=dict(color=('rgb(205, 12, 24)'))) trace2 = go.Scatter(y=max_population, x=simulated_years, mode='lines', line=dict(color=('rgb(205, 12, 24)'))) trace3 = go.Scatter(y=average_population, x=simulated_years, mode='lines') layout = go.Layout( title='Uncertainty analysis', xaxis=dict(title='Year'), yaxis=dict(title='Population'), ) data = [trace1, trace2, trace3] fig = go.Figure(data=data, layout=layout) image.save_as(fig, filename=''.join([path_to_figure, 'uncertanty', '.jpeg']))
def compare_profiles(obtained, given, year, title): if year not in list_of_years: print('No given data for this year') return y = [ y * 1000 for y in obtained[obtained['date'] == year][group].values.tolist()[0] ] trace1 = go.Scatter(x=group, y=y, mode='lines+markers', name='obtained') y = [ y * 1000 for y in given[given['date'] == year][group].values.tolist()[0] ] trace2 = go.Scatter(x=group, y=y, mode='lines+markers', name='given') layout = dict( title='Comparison of results for ' + str(year), xaxis=dict(title='Age group'), yaxis=dict(title='Amount of people'), ) data = [trace1, trace2] fig = go.Figure(data=data, layout=layout) plot(fig, image_filename="test.png") image.save_as(fig, filename=path_to_figure + title + '.jpeg')
def save_fig(figure, filename, out_directory='', dynamic=False, scale=None): """ Renders and saves plotly figures Parameters ---------- figure : plotly figure object plotly figure to render filename : str Name to save figure as out_directory : str Location to store the figure dynamic : bool Return dynamic (True) or static (False) scale : int Increase the resolution of saved image by 'scale' Returns ------- Dynamic or static image based on user request """ path = "{0}{1}".format(out_directory, filename) if not exists("{}.png".format(path)): name = "{}.png".format(path) image.save_as(figure, name, scale=scale) else: name = "{}_{}.png".format(path, int(time())) image.save_as(figure, name, scale=scale) if dynamic == True: return iplot(figure, filename=filename) elif dynamic == False: return Image("{}".format(name)) else: print("Invalid entry")
), hovermode='closest', #plot_bgcolor='#EFECEA', #set background color ) trace2= scatter_nodes([x,y],n,colors_graph) data=Data([trace2]) fig = Figure(data=data, layout=layout) #fig['layout'].update(annotations=make_annotations([x,y], n, colors_graph)) #offline.iplot(fig, filename='tst') image.save_as(fig,args.emb_file+"-grafico.png",scale=3) a = input('Pressione uma tecla para continuar: ') if(a and int(a) == 0): break ''' g.vp.vertex_name[v] g.vertex_index[v] g.vertex(index) '''