A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://python-graph-gallery.com/web-lollipop-with-colormap-and-arrow/ below:

Website Navigation


Lollipop plot with nice colormap, arrows and custom annotations

cmap = load_cmap('Coconut', cmap_type='continuous', reverse=True)
font = load_font('https://github.com/coreyhu/Urbanist/blob/main/fonts/ttf/Urbanist-Light.ttf?raw=true')
bold_font = load_font('https://github.com/coreyhu/Urbanist/blob/main/fonts/ttf/Urbanist-Medium.ttf?raw=true')
arrow_props = dict(color='black', width=0.5, head_width=2, head_length=5, radius=0.1)

fig, ax = plt.subplots(figsize=(15,8), dpi=300)
ax.set_axis_off()

for i, row in df.iterrows():
   year = row['Year']
   change = row['Change']
   color = cmap(change)
   ax.scatter(x=year, y=change, color=color)
   ax.plot([year,year], [0,change], color=color, alpha=0.8)
   
   if year % 20 == 0:
      ax.text(x=year, y=-0.6, s=f'{year:.0f}', font=font, size=15, ha='left')
ax.text(x=1881, y=-0.6, s=f'{1880}', font=font, size=15, ha='left')

h_lines = [-0.4, 0, 0.4, 0.8]
ax.hlines(y=h_lines, xmin=1881, xmax=2023, colors=[cmap(val) for val in h_lines], linewidth=1.2, zorder=-1, alpha=0.5)
for value in h_lines:
   ax.text(x=1877, y=value, s=f'{value}', font=font, color=cmap(value), size=9, va='center')

s = 'Global Land-Ocean Temperature Index'
ax_text(x=1881, y=1.1, s=s, font=font, size=35, ha='left')

s = 'Change in global surface temperature compared to the long-term average from 1951 to 1980'
ax_text(x=1881, y=0.94, s=s, font=font, size=16, ha='left', color='grey', alpha=0.7)

s = '<Graph>: barbierjoseph.com\n<Data Source>: NASA'
ax_text(x=1881, y=-0.7, s=s, font=font, size=8, ha='left', highlight_textprops=[{'font': bold_font}]*2)

s = 'Heat waves in Europe\nin the 1940s'
ax_text(x=1915, y=0.52, s=s, font=font, size=10, ha='left')
ax_arrow(
   tail_position=(1927, 0.43), head_position=(1938, 0.2), **arrow_props
)

s = 'Beginning of only positive\nvalues in global change'
ax_text(x=2018, y=-0.2, s=s, font=font, size=10, ha='right')
ax_arrow(
   tail_position=(1996, -0.22), head_position=(1980, -0.05), invert=True, **arrow_props
)

plt.savefig('../../static/graph/web-lollipop-with-colormap-and-arrow.png', dpi=300, bbox_inches='tight')
plt.show()

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4