Skip to content

Instantly share code, notes, and snippets.

@trolleway
Last active December 17, 2019 22:50
Show Gist options
  • Save trolleway/b65bf83f025f40766b26c13e534584cf to your computer and use it in GitHub Desktop.
Save trolleway/b65bf83f025f40766b26c13e534584cf to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
import matplotlib.dates as mdates
import dateutil
from matplotlib.ticker import (MultipleLocator, FormatStrFormatter,
AutoMinorLocator)
import datetime
# data sample
traintimes=dict()
stationcalls=dict()
traintimes['6502'] = ['13:45','14:45','15:45','15:55','16:10']
stationcalls['6502'] = [501, 512, 543, 543, 584]
traintimes['6503'] = ['14:05','14:55','15:00','15:10']
stationcalls['6503'] = [ 543, 512, 501, 512]
stations=dict()
stations[501]=u'Пригоркино'
stations[512]=u'Ведёркино'
stations[543]=u'пост 543 км.'
stations[584]=u'Духовкино'
# end of data
def convert_dates(times_list):
n = list()
for i in times_list:
#temp_dt = matplotlib.dates.datestr2num(i)
temp_dt = datetime.datetime.strptime(i, '%H:%M')
n.append(temp_dt)
print(i)
print(temp_dt)
return(n)
for k in traintimes:
temp_dict=dict()
temp_dict=convert_dates(traintimes[k])
traintimes[k] = temp_dict
fig, ax = plt.subplots()
# styling
train_line_style='g-'
hours = mdates.HourLocator()
hours_fmt = mdates.DateFormatter('%H:%M')
# station labels generate
station_names=list()
station_pks=list()
for elem in sorted(stations.items()) :
print(elem[0] , " ::" , elem[1] )
station_names.append(elem[1])
station_pks.append(elem[0])
plt.yticks(station_pks)
ax.set_yticklabels(station_names)
for trainnumber in traintimes:
print(trainnumber)
ax.plot(traintimes[trainnumber],stationcalls[trainnumber],train_line_style,label=trainnumber, color = 'gray', antialiased=False)
ax.set_ylabel(r'stations')
ax.xaxis.set_major_locator(hours)
ax.xaxis.set_major_formatter(hours_fmt)
plt.gcf().autofmt_xdate()
ax.grid(True)
plt.legend(title='Trains:')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment