Sélectionner une révision Git
graph.py 3,49 Kio
"""
Module for graphing
"""
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
def hist_distributivity_graph(N,RESOLUTION,seed,data):
"""
graphs histograms
see values function in main module
"""
plt.clf()
for name in data:
print("building "+str(name)+" histogram...")
xlabel= "Value"
ylabel="Count"
title_name= name +"\n N = "+str(N)+"\n seed = "+str(seed)
graph=sns.displot(data[name], kde=True)
graph.set(title=title_name)
graph.set_axis_labels(xlabel,ylabel)
graph.savefig(name+'_hist.png', bbox_inches='tight')
return
def ecdf_graph(N,RESOLUTION,seed,data):
"""
graphs histograms
see values function in main module
"""
plt.clf()
for name in data:
print("building "+str(name)+" ecdf...")
xlabel= "Value"
ylabel="Cumulative Probability"
title_name= name +"\n N = "+str(N)+"\n seed = "+str(seed)
if N==0:
title_name= name +"\n seed = "+str(seed)
graph=sns.displot(data[name], kind="ecdf")
graph.set(title=title_name)
graph.set_axis_labels(xlabel,ylabel)
graph.savefig(name+'_ecdf.png', bbox_inches='tight')
return
def compare_ecdf(N, RESOLUTION, seed, data):
"""
Create graphs superposing ecdf
"""
plt.clf()
BW = 0.337
name = "compare_ecdf_"
for e in data:
name += e+"_"
#subdata = {k : data[k] for k in names}
print("graphing "+str(name)+"...")
xlabel = "Value"
ylabel = "Density"
title_name="N = "+str(N)+"\n seed = "+str(seed)
if N == 0:
title_name = "seed = "+str(seed)
graph=sns.displot(data,legend=True
, kind="ecdf")
graph.set(title=title_name)
plt.xlabel(xlabel)
plt.ylabel(ylabel)
#plt.legend()
plt.savefig(name+'.png', bbox_inches='tight')
return
def compare(N, RESOLUTION, seed, data):
"""
Create graphs superposing two, already generated,
distributivity
"""
plt.clf()
BW = 0.337
name = "compare_"
for e in data:
name += e+"_"
#subdata = {k : data[k] for k in names}
print("graphing "+str(name)+"...")
xlabel = "Value"
ylabel = "Density"
title_name="N = "+str(N)+"\n seed = "+str(seed)
if N == 0:
title_name = "seed = "+str(seed)
for e in data:
graph=sns.kdeplot(data[e],legend=True,bw_adjust=BW,common_norm=False
,label=str(e))
graph.set(title=title_name)
plt.xlabel(xlabel)
plt.ylabel(ylabel)
graph.axes.set
plt.legend()
plt.savefig(name+'.png', bbox_inches='tight')
return
def lineplot_wrap(data, xlabel, ylabel, title, iterN):
plt.clf()
print("graphing "+str(title)+"...")
for e in data:
plt.plot(iterN, data[e], marker="o", label="seed="+str(e))
#graph = sns.lineplot(data, legend=True, x=iterN)
plt.title(title)
plt.legend()
plt.xscale('log')
plt.xlabel(xlabel)
plt.ylabel(ylabel)
plt.savefig(title.replace(" ", "_")+".png", bbox_inches="tight")
def lineplot_mean_alot(data, xlabel, ylabel, title, iterN):
plt.clf()
print("graphing "+str(title)+"...")
for e in data:
plt.plot(iterN, data[e], marker="o", alpha=0.05
, color="red")
plt.plot(iterN, [0.5]*len(iterN), color="blue",linestyle='dotted')
plt.title(title)
plt.xscale('log')
plt.xlabel(xlabel)
plt.ylabel(ylabel)
plt.savefig(title+".png", bbox_inches="tight")