Skip to content
Snippets Groups Projects
Unverified Commit e28f1065 authored by Benjamin Loison's avatar Benjamin Loison
Browse files

Add `plot_statistics_one.py`

parent 50e4e789
No related branches found
No related tags found
No related merge requests found
import json
import math
import matplotlib.pyplot as plt
SHOW_TARGET_RECOMPUTATION = False
with open('data.json') as f:
data = json.load(f)
with open('data_constant_difficulty.json') as f:
dataConstantDifficulty = json.load(f)
fig, targetsAxis = plt.subplots()
fig.subplots_adjust(right = 0.8)
fig.subplots_adjust(bottom = 0.4)
compressedScoreAxis = targetsAxis.twinx()
axes = [targetsAxis, targetsAxis.twinx(), compressedScoreAxis, targetsAxis.twinx(), compressedScoreAxis]
targets = data['targets']
for x, (target, nextTarget) in enumerate(zip(targets, targets[1:])):
if nextTarget < target:
firstTargetDecreaseCurve = plt.axvline(x = x, color = 'purple', label = 'first target decrease')
break
targetRecomputationCurve = []
if SHOW_TARGET_RECOMPUTATION:
for x in range(0, len(targets), 2016):
targetRecomputationCurve = [plt.axvline(x = x, alpha = 0.1, label = 'target recomputation')]
for x, (target, nextTarget) in enumerate(zip(targets, targets[1:])):
if nextTarget > target:
targetIncreaseCurve = plt.axvline(x = x, alpha = 0.5, color = 'red', label = 'target increase')
axesColors = ['blue', 'green', 'brown', 'orange', 'brown']
axesLabels = ['targets', 'compressed blockchain size (in blocks)', 'compressed blockchain score', 'constant difficulty compressed blockchain size (in blocks)', 'constant difficulty compressed blockchain score']
axesYValues = [targets, data['compressSize'], data['compressScore'], dataConstantDifficulty['compressSize'], dataConstantDifficulty['compressScore']]
curves = []
for curvesIndex, (axis, color, label, yValues) in enumerate(zip(axes, axesColors, axesLabels, axesYValues)):
dashes = (None, None) if curvesIndex != 4 else [1, 25]
alpha = 1 if curvesIndex != 3 else 0.5
curves += axis.plot(yValues, label = label, color = color, dashes = dashes, alpha = alpha)
targetsAxis.set_yscale('log', base=2)
axes[2].spines.right.set_position(('axes', 1.1))
axes[2].set_yscale('log')
axes[-2].spines.right.set_position(('axes', 1.2))
legendNewLine = targetsAxis.plot([], [], color='none', label=' ')
curves.insert(-2, legendNewLine[0])
curves += legendNewLine + targetRecomputationCurve + [firstTargetDecreaseCurve] + [targetIncreaseCurve]
labels = [curve.get_label() for curve in curves]
plt.legend(curves, labels, loc='upper center', framealpha=1, bbox_to_anchor=(0.5, -0.125))
targetsAxis.set_xlabel('Block height')
for ax, color in zip(axes, axesColors):
ax.tick_params(axis='y', colors=color)
title = 'Variable difficulty Bitcoin compressed blockchain evolution'
plt.title(title)
#plt.show()
fig.set_size_inches((11.2, 7.5), forward=False)
plt.savefig(f'{title.lower().replace(" ", "_")}.svg')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment