Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- import numpy as np
- import matplotlib.pyplot as plt
- import matplotlib.cm as cm
- def jahr_zweistellig(jahr):
- if jahr is None:
- return None
- return int(jahr) if len(jahr) > 2 else int('20'+jahr)
- data = []
- with open('data.txt', 'r') as f:
- for line in f:
- line = line.rstrip()
- m = re.match(
- '(?P<slot>[0-9]+)[.]?[ ]+' +
- '(?P<user>[^,;]*)[,;]\s*' +
- '((?P<modell>.*?)[,;]\s*)+?' +
- '(B[jJ][.]?\s*((?P<baujahr_monat>[0-9]{2,4})/)?(?P<baujahr_jahr>[0-9]{2,4}),\s*)?' +
- '(EZ[.]?\s*((?P<ez_monat>[0-9]{2,4})/)?(?P<ez_jahr>[0-9]{2,4}),\s*)?' +
- '((?P<zellen>(80|88))(\s*Zellen|er),\s*)?'
- '((?P<km>[0-9.,]+)\s*(km)?,?\s*)?'
- '((?P<ah>[0-9.,]+)\s*([aA][hH]),?\s*)?'
- '.*', line)
- if m:
- g = m.groupdict()
- data.append({
- 'Ah': None if g['ah'] is None else float(g['ah'].replace(',', '.')),
- 'BJ': jahr_zweistellig(g.get('baujahr_jahr')),
- 'EZ': jahr_zweistellig(g.get('ez_jahr')),
- 'km': int(re.sub('[^0-9]', '', g.get('km'))) if g.get('km') is not None else None,
- })
- #print(' matched: '+line)
- else:
- print('Not matched: '+line)
- x = {}
- y = {}
- for d in data:
- if d['Ah'] is None or d['km'] is None:
- continue
- jahr = d['BJ'] if d['BJ'] is not None else d['EZ']
- if jahr not in x:
- x[jahr] = []
- y[jahr] = []
- x[jahr].append(d['km']/1000)
- y[jahr].append(d['Ah'])
- jahre = set(x.keys())
- jahre.remove(None)
- jahre = list(jahre)
- jahre.sort()
- farben = cm.rainbow(np.linspace(0, 1, len(jahre)))
- for jahr, farbe in zip(jahre, farben):
- plt.scatter(x[jahr], y[jahr], color=farbe, label=jahr)
- plt.xticks(np.arange(0,
- max(max(x.values())) + 1,
- 10.0))
- plt.xlabel('Kilometerstand * 1000')
- plt.ylabel('Kapazität (Ah)')
- plt.legend()
- plt.title('Drillinge')
- plt.savefig('plot.png', bbox_inches='tight', dpi=300)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement