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

Simplify `plot_statistics.py` code

parent e9a2a534
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@ with open('data.json') as f:
fig, targetsAxis = plt.subplots()
fig.subplots_adjust(right = 0.8)
axes = [targetsAxis, targetsAxis.twinx(), targetsAxis.twinx()]
targets = [math.log2(target) for target in data['targets']]
......@@ -17,38 +18,33 @@ for x, (target, nextTarget) in enumerate(zip(targets, targets[1:])):
firstTargetDecreaseCurve = plt.axvline(x = x, color = 'purple', label = 'first target decrease')
break
targetRecomputationCurve = []
if SHOW_TARGET_RECOMPUTATION:
for x in range(0, len(data['targets']), 2016):
targetRecomputationCurve = plt.axvline(x = x, alpha = 0.1, label = 'target recomputation')
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')
targetsColor = 'blue'
targetsAxis.plot(targets, label = 'target', color = targetsColor)
targetsAxis.set_ylabel('targets', color = targetsColor)
axesColors = ['blue', 'green', 'brown']
axesLabels = ['targets', 'compressed blockchain size (in blocks)', 'compressed blockchain score']
axesYValues = [targets, data['compressSize'], data['compressScore']]
compressSizeAxis = targetsAxis.twinx()
compressScoreAxis = targetsAxis.twinx()
for axis, color, label, yValues in zip(axes, axesColors, axesLabels, axesYValues):
axis.plot(yValues, color = color)
axis.set_ylabel(label, color = color)
compressScoreAxis.spines.right.set_position(('axes', 1.15))
axes[1].spines.right.set_position(('axes', 1.1))
compressSizeColor = 'green'
compressSizeAxis.plot(data['compressSize'], color = compressSizeColor)
compressSizeAxis.set_ylabel('compressed blockchain size (in blocks)', color = compressSizeColor)
compressScoreColor = 'brown'
compressScoreAxis.plot(data['compressScore'], color = compressScoreColor)
compressScoreAxis.set_ylabel('compressed blockchain score', color = compressScoreColor)
curves = ([targetRecomputationCurve] if SHOW_TARGET_RECOMPUTATION else []) + [firstTargetDecreaseCurve] + [targetIncreaseCurve]
curves = targetRecomputationCurve + [firstTargetDecreaseCurve] + [targetIncreaseCurve]
labels = [curve.get_label() for curve in curves]
plt.legend(curves, labels, loc='upper center', framealpha=1)
ax1.set_xlabel('Block height')
for ax, color in zip([targetsAxis, compressSizeAxis, compressScoreAxis], [targetsColor, compressSizeColor, compressScoreColor]):
for ax, color in zip(axes, axesColors):
ax.tick_params(axis='y', colors=color)
plt.title('Variable difficulty Bitcoin compressed blockchain evolution')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment