Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Mining in Logarithmic Space
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LOISON Benjamin
Mining in Logarithmic Space
Commits
09c2cb5d
Unverified
Commit
09c2cb5d
authored
1 year ago
by
Benjamin Loison
Browse files
Options
Downloads
Patches
Plain Diff
Notably add time display to x-axis
parent
54ce05cd
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
plot_statistics_one.py
+35
-12
35 additions, 12 deletions
plot_statistics_one.py
with
35 additions
and
12 deletions
plot_statistics_one.py
+
35
−
12
View file @
09c2cb5d
import
json
import
math
import
matplotlib.pyplot
as
plt
import
matplotlib.dates
as
mdates
import
datetime
SHOW_TARGET_RECOMPUTATION
=
False
...
...
@@ -8,37 +10,52 @@ with open('data.json') as f:
data
=
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
]
for
key
in
data
:
data
[
key
]
=
data
[
key
][:
428_078
]
targets
=
data
[
'
targets
'
]
timestamps
=
[
datetime
.
datetime
.
fromtimestamp
(
timestamp
)
for
timestamp
in
data
[
'
timestamps
'
]]
for
x
,
(
target
,
nextTarget
)
in
enumerate
(
zip
(
targets
,
targets
[
1
:])):
if
nextTarget
<
target
:
firstTargetDecreaseCurve
=
plt
.
axvline
(
x
=
x
,
color
=
'
purple
'
,
label
=
'
first target decrease
'
)
firstTargetDecreaseCurve
=
plt
.
axvline
(
x
=
timestamps
[
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
'
)]
targetRecomputationCurve
=
[
plt
.
axvline
(
x
=
timestamps
[
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
'
)
targetIncreaseCurve
=
plt
.
axvline
(
x
=
timestamps
[
x
]
,
alpha
=
0.5
,
color
=
'
red
'
,
label
=
'
target increase
'
)
axesColors
=
[
'
blue
'
,
'
green
'
,
'
brown
'
]
axesLabels
=
[
'
targets
'
,
'
compressed blockchain size (in blocks)
'
,
'
compressed blockchain score
'
]
axesYValues
=
[
targets
,
data
[
'
compressSize
'
],
data
[
'
compressScore
'
]]
blockHeightsCache
=
{}
class
CustomDateFormatter
(
mdates
.
ticker
.
Formatter
):
def
__call__
(
self
,
x
,
pos
=
0
):
datetime_
=
mdates
.
num2date
(
x
)
if
not
x
in
blockHeightsCache
:
for
timestampsIndex
,
timestamp
in
enumerate
(
timestamps
):
if
datetime_
.
timestamp
()
<=
timestamp
.
timestamp
():
blockHeightsCache
[
x
]
=
timestampsIndex
break
blockHeight
=
f
'
-
{
blockHeightsCache
[
x
]
}
'
if
x
in
blockHeightsCache
else
''
result
=
datetime_
.
strftime
(
'
%m/%Y
'
)
+
blockHeight
return
result
plt
.
gca
().
xaxis
.
set_major_formatter
(
CustomDateFormatter
())
curves
=
[]
for
curvesIndex
,
(
axis
,
color
,
label
,
yValues
)
in
enumerate
(
zip
(
axes
,
axesColors
,
axesLabels
,
axesYValues
)):
curves
+=
axis
.
plot
(
yValues
,
label
=
label
,
color
=
color
)
curves
+=
axis
.
plot
(
timestamps
,
yValues
,
label
=
label
,
color
=
color
)
plt
.
gcf
().
autofmt_xdate
()
targetsAxis
.
set_yscale
(
'
log
'
,
base
=
2
)
...
...
@@ -46,12 +63,18 @@ axes[2].spines.right.set_position(('axes', 1.1))
axes
[
2
].
set_yscale
(
'
log
'
)
legendNewLine
=
targetsAxis
.
plot
([],
[],
color
=
'
none
'
,
label
=
'
'
)
curves
.
insert
(
-
2
,
legendNewLine
[
0
])
curves
+=
legendNewLine
+
targetRecomputationCurve
+
[
firstTargetDecreaseCurve
]
+
[
targetIncreaseCurve
]
for
curve
in
targetRecomputationCurve
+
[
firstTargetDecreaseCurve
,
targetIncreaseCurve
][::
-
1
]:
curves
.
insert
(
1
,
curve
)
curves
.
insert
(
-
2
,
legendNewLine
[
0
])
labels
=
[
curve
.
get_label
()
for
curve
in
curves
]
plt
.
legend
(
curves
,
labels
,
loc
=
'
upper center
'
,
framealpha
=
1
,
bbox_to_anchor
=
(
0.5
,
-
0.125
))
plt
.
legend
(
curves
,
labels
,
loc
=
'
upper center
'
,
framealpha
=
1
,
bbox_to_anchor
=
(
0.5
,
-
0.18
))
fig
.
subplots_adjust
(
left
=
0.035
)
fig
.
subplots_adjust
(
right
=
0.875
)
fig
.
subplots_adjust
(
bottom
=
0.32
)
fig
.
subplots_adjust
(
top
=
0.965
)
targetsAxis
.
set_xlabel
(
'
Block height
'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment