Last active
August 23, 2022 18:28
-
-
Save lmeulen/dd6ef7f92ac5e89d3c23058e2e784388 to your computer and use it in GitHub Desktop.
ergast_diver_comp_graph
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fig, ax = plt.subplots(figsize=(8,3.5)) | |
driver_clrs = [stats.get_driver_color(dr[0]), stats.get_driver_color(dr[1]) ] | |
ys = ['Points', 'Points', 'Wins', 'Wins', 'Podiums', 'Podiums', | |
'Quali', 'Quali', 'Race', 'Race'] | |
xmaxs = [-pnts[0]/max(pnts), pnts[1]/max(pnts), \ | |
-wins[0]/max(wins), wins[1]/max(wins), \ | |
-podia[0]/max(podia), podia[1]/max(podia), \ | |
-quali[0]/max(quali), quali[1]/max(quali), \ | |
-race[0]/max(race), race[1]/max(race)] | |
labels = [ pnts[0], pnts[1], wins[0], wins[1], podia[0], podia[1], \ | |
quali[0], quali[1], race[0], race[1] ] | |
clrs = np.tile([driver_clrs[0], driver_clrs[1]], 5) | |
rects = ax.hlines(y=ys, xmin=0, xmax=xmaxs, color=clrs, alpha=0.4, linewidth=30) | |
for nm, lbl, vl in zip(ys, labels, xmaxs): | |
label = ax.annotate(str(int(lbl)), xy=(vl, nm), xytext=(5 if vl > 0 else -20, 0), | |
textcoords="offset points", ha="left", va='center') | |
ax.set_xlim(-1.25, 1.25) | |
ax.spines['top'].set_visible(False) | |
ax.spines['right'].set_visible(False) | |
ax.spines['bottom'].set_visible(False) | |
ax.spines['left'].set_visible(False) | |
ax.axvline(0, color='black') | |
plt.tick_params(axis='x', which='both', bottom=False, top=False, labelbottom=False) | |
ax.set_title('Comparison {} to {}'.format(driver1, driver2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment