masterthesis/codes/node-ranking/plot_in_out_avg.py

46 lines
1.2 KiB
Python
Raw Normal View History

2022-04-19 18:38:01 +02:00
#!/usr/bin/env python3
from datetime import datetime
import matplotlib.pyplot as plt
import numpy as np
import json
def load_data(path):
with open(path, 'r') as f:
return json.load(f)
def main():
data = load_data('./tmp_plot.json')
times = []
avg_in = []
avg_out = []
known_in = []
known_out = []
number_of_nodes = []
for k, v in sorted(data.items(), key = lambda kv: kv[0]):
times.append(datetime.fromtimestamp(float(k)))
avg_in.append(v['avg_in'])
avg_out.append(v['avg_out'])
known_in.append(v['known_in'])
2022-04-21 23:05:11 +02:00
# known_out.append(v['known_out'])
2022-04-19 18:38:01 +02:00
number_of_nodes.append(v['number_of_nodes'])
fig, ax = plt.subplots()
ax.plot(times, avg_in, label='Avg. In')
# ax.plot(times, avg_out, label='Avg. Out')
ax.plot(times, known_in, label='Known In')
2022-04-21 23:05:11 +02:00
# ax.plot(times, known_out, label='Known Out')
ax.plot(times, number_of_nodes, label='Total number of nodes')
2022-04-19 18:38:01 +02:00
ax.set_title(f'Average edge count per hour')
fig.autofmt_xdate()
fig.legend()
2022-04-21 23:05:11 +02:00
ax.set_ylim(ymin=0)
2022-04-19 18:38:01 +02:00
plt.savefig(f'./tmp_plot.png')
# print('created sr plot')
plt.show()
if __name__ == '__main__':
main()