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

Simplify `CustomDateFormatter`

parent 04ade4f5
No related branches found
No related tags found
No related merge requests found
......@@ -44,35 +44,18 @@ axesColors = ['blue', 'green', 'brown', 'orange', 'brown', 'red', 'purple']
axesLabels = ['targets', 'compressed blockchain size (in blocks)', 'compressed blockchain score', 'constant difficulty compressed blockchain size (in blocks)', 'constant difficulty compressed blockchain score', 'compressed blockchain size keeping all blocks since last m higher block (in blocks)', 'compressed blockchain score keeping all blocks since last m higher block']
axesYValues = [targets, data['compressSize'], data['compressScore'], dataConstantDifficulty['compressSize'], dataConstantDifficulty['compressScore'], dataKeepingAllBlocksSinceLastMHigherBlock['compressSize'], dataKeepingAllBlocksSinceLastMHigherBlock['compressScore']]
class CustomDateFormatter(ticker.Formatter):
"""
Format a tick (in days since the epoch) with a
`~datetime.datetime.strftime` format string.
"""
def __init__(self, fmt, tz=None):
"""
Parameters
----------
fmt : str
`~datetime.datetime.strftime` format string
tz : str or `~datetime.tzinfo`, default: :rc:`timezone`
Ticks timezone. If a string, *tz* is passed to `dateutil.tz`.
"""
self.tz = _get_tzinfo(tz)
self.fmt = fmt
class CustomDateFormatter(mdates.ticker.Formatter):
def __call__(self, x, pos=0):
result = num2date(x, self.tz).strftime(self.fmt)
result = mdates.num2date(x).strftime('%m/%Y')
return result
plt.gca().xaxis.set_major_formatter(CustomDateFormatter('%m/%Y'))
plt.gca().xaxis.set_major_formatter(CustomDateFormatter())
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
# TODO: remove below
# TODO: remove below, could maybe precise file names in scripts not to mess up
# Due to not having exported `timestamps` for every execution:
comparableLength = min(len(timestamps), len(yValues))
curves += axis.plot(timestamps[:comparableLength], yValues[:comparableLength], label = label, color = color, dashes = dashes, alpha = alpha)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment