Make plot_dates.py
leverage photo exifs
This commit is contained in:
@@ -5,46 +5,36 @@ import numpy as np
|
|||||||
|
|
||||||
import matplotlib.dates as mdates
|
import matplotlib.dates as mdates
|
||||||
|
|
||||||
try:
|
from PIL import Image
|
||||||
# Try to fetch a list of Matplotlib releases and their dates
|
from PIL.ExifTags import TAGS
|
||||||
# from https://api.github.com/repos/matplotlib/matplotlib/releases
|
|
||||||
import json
|
|
||||||
import urllib.request
|
|
||||||
|
|
||||||
url = 'https://api.github.com/repos/matplotlib/matplotlib/releases'
|
import os
|
||||||
url += '?per_page=100'
|
|
||||||
data = json.loads(urllib.request.urlopen(url, timeout=1).read().decode())
|
|
||||||
|
|
||||||
dates = []
|
os.chdir('photos')
|
||||||
names = []
|
|
||||||
for item in data:
|
|
||||||
if 'rc' not in item['tag_name'] and 'b' not in item['tag_name']:
|
|
||||||
dates.append(item['published_at'].split("T")[0])
|
|
||||||
names.append(item['tag_name'])
|
|
||||||
# Convert date strings (e.g. 2014-10-18) to datetime
|
|
||||||
dates = [datetime.strptime(d, "%Y-%m-%d") for d in dates]
|
|
||||||
|
|
||||||
except Exception:
|
names = []
|
||||||
# In case the above fails, e.g. because of missing internet connection
|
dates = []
|
||||||
# use the following lists as fallback.
|
|
||||||
names = ['v2.2.4', 'v3.0.3', 'v3.0.2', 'v3.0.1', 'v3.0.0', 'v2.2.3',
|
|
||||||
'v2.2.2', 'v2.2.1', 'v2.2.0', 'v2.1.2', 'v2.1.1', 'v2.1.0',
|
|
||||||
'v2.0.2', 'v2.0.1', 'v2.0.0', 'v1.5.3', 'v1.5.2', 'v1.5.1',
|
|
||||||
'v1.5.0', 'v1.4.3', 'v1.4.2', 'v1.4.1', 'v1.4.0']
|
|
||||||
|
|
||||||
dates = ['2019-02-26', '2019-02-26', '2018-11-10', '2018-11-10',
|
for fileName in sorted(os.listdir()):
|
||||||
'2018-09-18', '2018-08-10', '2018-03-17', '2018-03-16',
|
#print(fileName)
|
||||||
'2018-03-06', '2018-01-18', '2017-12-10', '2017-10-07',
|
if fileName.endswith('.JPG'):
|
||||||
'2017-05-10', '2017-05-02', '2017-01-17', '2016-09-09',
|
image = Image.open(fileName)
|
||||||
'2016-07-03', '2016-01-10', '2015-10-29', '2015-02-16',
|
imageExif = image.getexif()
|
||||||
'2014-10-26', '2014-10-18', '2014-08-26']
|
dateTimeKey = list(TAGS.keys())[list(TAGS.values()).index('DateTime')]
|
||||||
|
dateTime = imageExif[dateTimeKey]
|
||||||
|
#print(dateTime)
|
||||||
|
names += [fileName.replace('DSC0', '').replace('.JPG', '')]
|
||||||
|
dates += [dateTime]
|
||||||
|
#break
|
||||||
|
|
||||||
# Convert date strings (e.g. 2014-10-18) to datetime
|
# Convert date strings to datetime
|
||||||
dates = [datetime.strptime(d, "%Y-%m-%d") for d in dates]
|
dates = [datetime.strptime(d, "%Y:%m:%d %H:%M:%S") for d in dates]
|
||||||
|
|
||||||
# Choose some nice levels
|
# Choose some nice levels
|
||||||
levels = np.tile([-5, 5, -3, 3, -1, 1],
|
NUMBER_OF_LEVELS = 10
|
||||||
int(np.ceil(len(dates)/6)))[:len(dates)]
|
actualLevels = range(-NUMBER_OF_LEVELS * 2 + 1, NUMBER_OF_LEVELS * 2 , 2)
|
||||||
|
levels = np.tile(actualLevels,
|
||||||
|
int(np.ceil(len(dates)/len(actualLevels))))[:len(dates)]
|
||||||
|
|
||||||
# Create figure and plot a stem plot with the date
|
# Create figure and plot a stem plot with the date
|
||||||
fig, ax = plt.subplots(figsize=(8.8, 4), layout="constrained")
|
fig, ax = plt.subplots(figsize=(8.8, 4), layout="constrained")
|
||||||
@@ -62,8 +52,7 @@ for d, l, r in zip(dates, levels, names):
|
|||||||
verticalalignment="bottom" if l > 0 else "top")
|
verticalalignment="bottom" if l > 0 else "top")
|
||||||
|
|
||||||
# format x-axis with 4-month intervals
|
# format x-axis with 4-month intervals
|
||||||
ax.xaxis.set_major_locator(mdates.MonthLocator(interval=4))
|
ax.xaxis.set_major_formatter(mdates.DateFormatter("%Y:%m:%d %H:%M:%S"))
|
||||||
ax.xaxis.set_major_formatter(mdates.DateFormatter("%b %Y"))
|
|
||||||
plt.setp(ax.get_xticklabels(), rotation=30, ha="right")
|
plt.setp(ax.get_xticklabels(), rotation=30, ha="right")
|
||||||
|
|
||||||
# remove y-axis and spines
|
# remove y-axis and spines
|
||||||
@@ -71,4 +60,4 @@ ax.yaxis.set_visible(False)
|
|||||||
ax.spines[["left", "top", "right"]].set_visible(False)
|
ax.spines[["left", "top", "right"]].set_visible(False)
|
||||||
|
|
||||||
ax.margins(y=0.1)
|
ax.margins(y=0.1)
|
||||||
plt.show()
|
plt.show()
|
Reference in New Issue
Block a user